Racing robots

Dependencies:   EthernetInterface SPI_TFT_ILI9341 Stopwatch TFT_fonts TextLCD mbed-rtos mbed

Fork of rtos_basic by mbed official

Files at this revision

API Documentation at this revision

Comitter:
mbed5_khbo
Date:
Wed Apr 08 17:29:56 2015 +0000
Parent:
6:209f4db62daf
Child:
8:0499c9bedfca
Commit message:
voor sven

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
HY-1_8TFT_fonts_ST7735.lib Show annotated file Show diff for this revision Revisions of this file
SPI_TFT_ILI9341.lib Show annotated file Show diff for this revision Revisions of this file
Stopwatch.lib Show annotated file Show diff for this revision Revisions of this file
TFT_fonts.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Wed Apr 08 17:29:56 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#5887ae6c0c2c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HY-1_8TFT_fonts_ST7735.lib	Wed Apr 08 17:29:56 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/star297/code/HY-1_8TFT_fonts_ST7735/#867e1c9276d0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SPI_TFT_ILI9341.lib	Wed Apr 08 17:29:56 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/SPI_TFT_ILI9341/#b2b3e5430f81
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Stopwatch.lib	Wed Apr 08 17:29:56 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mdomino/code/Stopwatch/#3328857bf625
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT_fonts.lib	Wed Apr 08 17:29:56 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/TFT_fonts/#76774250fcec
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Apr 08 17:29:56 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- a/main.cpp	Tue Jun 04 16:01:32 2013 +0100
+++ b/main.cpp	Wed Apr 08 17:29:56 2015 +0000
@@ -1,21 +1,196 @@
 #include "mbed.h"
 #include "rtos.h"
- 
+#include "EthernetInterface.h"
+#include "stdio.h"
+#include "SPI_TFT_ILI9341.h"
+#include "string"
+#include "Arial12x12.h"
+#include "Arial24x23.h"
+#include "Arial28x28.h"
+#include "font_big.h"
+#include "Stopwatch.h"
+
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+DigitalOut rst1(p30);
+DigitalIn  sensorBasis(p12);
+DigitalIn  up(p15);
+I2C i2c(p28, p27);
+Serial xbee1(p9, p10);
+const int addr = 0x90;
+string rondeTijden[3];
+int stukCircuit=0;
+int tellerS=0,tellerM=0,data=125,status,i=3;
+int start,i2cinfo1,i2cinfo2,i2cinfo3;
+bool send;
+char cmd[2];
+Stopwatch klok;
+
+LocalFileSystem local("local");
  
-void led2_thread(void const *args) {
+extern unsigned char p1[];  // the mbed logo graphic
+ 
+// the display has a backlight switch on board 
+DigitalOut LCD_LED(p21);       
+ 
+// the TFT is connected to SPI pin 5-7
+SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p15, p16,"TFT"); // mosi, miso, sclk, cs, reset, dc
+  
+
+void rondeTijden_thread(void const *args) {
     while (true) {
-        led2 = !led2;
-        Thread::wait(1000);
+      if(sensorBasis == 1)
+      {
+         if(start == 0)
+         {
+            Thread::wait(500);
+            klok=Stopwatch();
+            klok.start();
+            start=1;
+         }
+         else
+         {
+            start=0;
+            send=true;
+            rondeTijden[2]=rondeTijden[1];
+            rondeTijden[1]=rondeTijden[0];
+            rondeTijden[0]=klok.getTime();
+        }
+      }
+      else
+      {
+          led4=0;
+      }       
     }
 }
  
-int main() {
-    Thread thread(led2_thread);
-    
+
+void meetStation_thread(void const *args) {
     while (true) {
-        led1 = !led1;
-        Thread::wait(500);
+        i2c.read(addr, cmd, 2);
+        switch(cmd[0])
+        {
+            case 0:
+            if(cmd[1]==1)
+            {
+                tellerS=1;
+            }
+            break;
+            case 1:
+            if(cmd[1]==1)
+            {
+                tellerS=2;
+            }
+            break;
+            case 2:
+            if(cmd[1]==1)
+            {
+                tellerS=3;
+            }
+            break;
+        }  
     }
 }
+
+void ethernet_receive_thread(void const *args) {
+    while(1)
+    {
+    
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    //lcd.locate(0,10);
+    //lcd.printf("IP Address is %s\n", eth.getIPAddress());
+    TCPSocketConnection sock;
+    sock.connect("192.168.0.100", 8006);
+    char buffer[10];
+    int ret;
+    ret = sock.receive(buffer, sizeof(buffer)-1);
+    if(buffer[0]==1)
+    {
+        switch(buffer[1])
+        {
+            case 'G':
+            xbee1.putc(0x01);
+            break;
+            case 'S':
+            xbee1.putc(0x02);
+            break;
+        }   
+    }
+    
+    }
+ }
+ 
+ 
+ 
+ void ethernet_transmit_thread(void const *args) {
+    while(1)
+    {
+    
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    //lcd.locate(0,10);
+    //lcd.printf("IP Address is %s\n", eth.getIPAddress());
+    TCPSocketConnection sock;
+    sock.connect("192.168.0.100", 8005);
+    if(send)
+    {
+       char http_cmd[] = "12.56";
+       sock.send_all(http_cmd, sizeof(http_cmd)-1);
+       send=false;
+       } 
+    
+    }
+ }
+ 
+ 
+int main() {
+    
+    xbee1.baud(115200);
+    Thread thread1(rondeTijden_thread);
+    Thread thread2(meetStation_thread);
+    rst1 = 0;
+    wait_ms(1);
+    rst1 = 1;
+    wait_ms(1);
+        
+       
+            
+            
+    LCD_LED = 1;            // backlite on
+    TFT.claim(stdout);        // send stdout to the TFT display
+        TFT.set_orientation(1);
+        TFT.background(White);    // set background to black
+        TFT.foreground(Black);    // set chars to white
+        TFT.cls();                // clear the screen
+    TFT.set_font((unsigned char*) Neu42x35);
+    TFT.locate(5,5);
+    TFT.printf("Racing robot");
+    
+    TFT.line(0,50,320,50,White);
+    TFT.set_font((unsigned char*) Arial24x23);
+    TFT.locate(5,55);
+    TFT.printf("LAPTIJDEN:");
+    xbee1.baud(115200);
+    
+    //thread3=new Thread(ethernet_receive_thread);
+    //thread4=new Thread(ethernet_transmit_thread);
+    while(1)
+    {
+        TFT.set_font((unsigned char*) Arial28x28);
+    TFT.locate(30,90);
+    TFT.printf(klok.getTime());
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.rect(10,170,110,210,Black);
+    TFT.fillrect(11,171,109,209,Green);
+    TFT.rect(110,170,210,210,Black);
+    TFT.fillrect(111,171,209,209,Red);
+    TFT.rect(210,170,310,210,Black);
+    TFT.fillrect(211,171,309,209,Red);
+    wait_ms(100);
+     }
+}
--- a/mbed-rtos.lib	Tue Jun 04 16:01:32 2013 +0100
+++ b/mbed-rtos.lib	Wed Apr 08 17:29:56 2015 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/mbed-rtos/
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed-rtos/#63988a2238f7
--- a/mbed.bld	Tue Jun 04 16:01:32 2013 +0100
+++ b/mbed.bld	Wed Apr 08 17:29:56 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac
\ No newline at end of file