Example application to connect the DISCO_F746NG board to thethings.iO

Dependencies:   BSP_DISCO_F746NG F7_Ethernet LCD_DISCO_F746NG NetworkAPI TS_DISCO_F746NG ThethingsiO_DISCO_F746NG mbed-dev mbed-rtos

Fork of TCP_Client_Example by Roy van Dam

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "TS_DISCO_F746NG.h"
00002 #include "LCD_DISCO_F746NG.h"
00003 #include "ThethingsiO_DISCO_F746NG.h"
00004 
00005 #define TOKEN "YOUR THING TOKEN"
00006 
00007 int result;
00008 
00009 LCD_DISCO_F746NG lcd;
00010 TS_DISCO_F746NG ts;
00011 
00012 int touched_left, touched_right ;
00013 stringstream temp_string;
00014 
00015 int main()
00016 {
00017     ThethingsiO_DISCO_F746NG thethings = ThethingsiO_DISCO_F746NG::ThethingsiO_DISCO_F746NG(TOKEN);
00018     //printf("IP Address is %s\n\r", interface.getIPAddress());
00019     TS_StateTypeDef TS_State;
00020     uint16_t x, y, x_ant, y_ant;
00021 
00022     touched_left = touched_right = 0;
00023     lcd.Clear(LCD_COLOR_BLACK);
00024 
00025     lcd.SetTextColor(LCD_COLOR_RED);
00026     lcd.DrawCircle(160, 136, 50);
00027     wait(0.1);
00028     lcd.SetTextColor(LCD_COLOR_RED);
00029     lcd.FillCircle(160, 136, 50);
00030     wait(1);
00031     lcd.SetTextColor(LCD_COLOR_GREEN);
00032     lcd.DrawCircle(320, 136, 50);
00033     wait(0.1);
00034     lcd.SetTextColor(LCD_COLOR_GREEN);
00035     lcd.FillCircle(320, 136, 50);
00036     wait(1);
00037     ts.Init(lcd.GetXSize(), lcd.GetYSize());
00038     wait(3);
00039 
00040     lcd.SetBackColor(LCD_COLOR_BLACK);
00041     lcd.SetTextColor(LCD_COLOR_WHITE);
00042     printf("\r\n");
00043     while (1) {
00044         ts.GetState(&TS_State);
00045         if (TS_State.touchDetected) {
00046             x = TS_State.touchX[0];
00047             y = TS_State.touchY[0];
00048             if ((x_ant != x) && (y_ant != y)) {
00049                 if ((x >= 110 && x <= 210)&&(y >= 86 && y <= 186)) {
00050                     touched_left++;
00051                     temp_string.str("");
00052                     temp_string << touched_left;
00053                     lcd.DisplayStringAt(400, LINE(1), (uint8_t *)temp_string.str().c_str(), CENTER_MODE);
00054                     thethings.thingWrite("demo", "1");
00055                 } else if ((x >= 270 && x <= 370)&&(y >= 86 && y <= 186)) {
00056                     touched_right++;
00057                     temp_string.str("");
00058                     temp_string << touched_right;
00059                     lcd.DisplayStringAt(110, LINE(1), (uint8_t *)temp_string.str().c_str(), CENTER_MODE);
00060                     thethings.thingWrite("demo", "2");
00061                 }
00062             }
00063             x_ant = x;
00064             y_ant = y;
00065         }
00066     }
00067 }