void startWebServer() { server.listen(80); server.addPath("/", onIndex); server.addPath("/lcd", onLcd); server.addPath("/volume", onVolume); server.addPath("/mute", onMute); server.addPath("/source", onSource); server.addPath("/state", onState); server.addPath("/power", onPower); server.addPath("/tune", onTune); server.addPath("/mixing", onMixing); server.addPath("/enhance", onEnhance); // Web Sockets configuration server.enableWebSockets(true); server.setWebSocketConnectionHandler(wsConnected); server.setWebSocketMessageHandler(wsMessageReceived); server.setWebSocketBinaryHandler(wsBinaryReceived); server.setWebSocketDisconnectionHandler(wsDisconnected); server.setDefaultHandler(onFile); Serial.println("\r\n=== WEB SERVER STARTED ==="); Serial.println(WifiStation.getIP()); lcd.clear(); lcd.setCursor(1,1); lcd.print(WifiStation.getIP()); }
void init() { Serial.begin(SERIAL_BAUD_RATE); Serial.systemDebugOutput(true); // Allow debug print to serial Serial.println("Sming. Let's do smart things!"); Wire.pins(2, 0); lcd.begin(16, 2); lcd.backlight(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("DATE: 00/00/0000"); lcd.setCursor(0, 1); lcd.print("TIME: 00:00"); // Station - WiFi client WifiStation.enable(true); WifiStation.config(WIFI_SSID, WIFI_PWD); // Put you SSID and Password here // set timezone hourly difference to UTC SystemClock.setTimeZone(7); // Run our method when station was connected to AP (or not connected) WifiStation.waitConnection(connectOk, 30, connectFail); // We recommend 20+ seconds at start }
void setPressure() { lcd.clear(); lcd.print("Baromethric"); lcd.setCursor(0, 1); lcd.print("10000"); lcd.print(" kPa"); }
void echoSerial(){ byte index=0; char outa[20]; char outb[20]; outb[0]='\0'; boolean foundData=false; while (Serial.available() > 0){ foundData=true; if(index < 19){ outa[index]=Serial.read(); index++; outa[index]= '\0'; }else{ if(index < 39){ outb[index-20]=Serial.read(); index++; outb[index-20]= '\0'; } } } if(foundData){ lcd.clear(); lcd.home(); lcd.print(outa); lcd.setCursor ( 0, 1 ); lcd.print(outb); } }
void setHumidity() { float newHumidity = dht.readHumidity(); lcd.clear(); lcd.print("Humidity"); lcd.setCursor(0, 1); lcd.print(newHumidity); lcd.print(" %"); }
void setTemperature() { float newTemperature = dht.readTemperature(false); lcd.clear(); lcd.print("Temperature"); lcd.setCursor(0, 1); lcd.print(newTemperature); lcd.print(" C"); }
void navigationReturnHome() { navigationSounds->play( soundUhoh ); currentNavigationDestination = currentNavigationHome; lcd.clear(); lcd.print( "Returning home!" ); lcd.setCursor(0, 2); lcd.print( "Next stop:" ); lcd.setCursor(0, 3); lcd.print( destinationList[currentNavigationHome] ); }
void loop() { int value = analogRead(TEMP_PIN); float celsius = ((value * 5.0) / 1024.0 - 0.5) * 100; float fahrenheit = (celsius * 9.0 / 5.0) + 32.0; String temperatureCelsius = String(celsius); String temperatureFahrenheit = String(fahrenheit); lcd.clear(); lcd.print(temperatureCelsius); lcd.print(" degrees C"); lcd.setCursor(0, 1); lcd.print(temperatureFahrenheit); lcd.print(" degrees F"); delay(5000); }
int step1() { //Wait for GPS lcd.clear(); lcd.println(F("Looking for GPS")); lcd.setCursor(0, 1); char str[32]; sprintf(str,"view:%2d fix:%2d", sats_view, sats_fix); lcd.print(str); delay(1000); if(millis() > sleep_time + 300000) digitalWrite(ON_PIN, 0); if(gps_fix == 3) return 1; else return 0; }
void DisplayClass::goSleep() { lcd.clear(); lcd.home(); lcd.print(F("Low Power Mode")); lcd.setCursor(0, 1); lcd.print(F("Going to sleep in:")); lcd.setCursor(0, 2); lcd.print(F("3")); DELAY_FUNC(333); for (uint8_t i = 0; i < 3; i++) { lcd.print(F(".")); DELAY_FUNC(333); } lcd.print(F("2")); DELAY_FUNC(333); for (uint8_t i = 0; i < 3; i++) { lcd.print(F(".")); DELAY_FUNC(333); } lcd.print(F("1")); DELAY_FUNC(333); for (uint8_t i = 0; i < 3; i++) { lcd.print(F(".")); DELAY_FUNC(333); } lcd.print(F("0!")); DELAY_FUNC(333); for (uint8_t i = 0; i < 3; i++) { noBacklight(); DELAY_FUNC(500); backlight(); DELAY_FUNC(500); } }
bool navigationCheckLocation() { while ( currentNavigationLocation < 0 ) { lcd.clear(); lcd.print( "Where am I starting?" ); lcdSelectLocation(); while ( digitalRead(LCD_UP_PIN) == HIGH || digitalRead(LCD_DOWN_PIN) == HIGH || digitalRead(LCD_PLAY_PIN) == HIGH ) { if ( digitalRead(LCD_UP_PIN) == LOW ) { navigationSounds->play( soundUp ); if ( --lcdCurrentSelection < 0 ) lcdCurrentSelection = MAP_LOCATION_COUNT - 1; delay(250); //debounce time break; } if ( digitalRead(LCD_DOWN_PIN) == LOW ) { navigationSounds->play( soundDown ); if ( ++lcdCurrentSelection == MAP_LOCATION_COUNT ) lcdCurrentSelection = 0; delay(250); //debounce time break; } if ( digitalRead(LCD_PLAY_PIN) == LOW ) { navigationSounds->play( soundUhoh ); currentNavigationLocation = lcdCurrentSelection; currentNavigationHome = lcdCurrentSelection; /* Serial.print( "Current Location: " ); Serial.print( currentNavigationLocation ); Serial.print( ": " ); Serial.println( destinationList[currentNavigationLocation] ); */ delay(250); //debounce time break; } } return false; } return true; }
void updatelcd() { lcd.clear(); lcd.setCursor(0,0); lcd.print("XT"); lcd.setCursor(3,0); lcd.print(_XEncoderTicks); lcd.setCursor(10,0); lcd.print("XI"); lcd.setCursor(13,0); lcd.print(_XEncoderIndex); lcd.setCursor(18,0); lcd.print("X"); lcd.setCursor(19,0); lcd.print(">" + _XMinPinSet); lcd.setCursor(17,0); lcd.print("<" + _XMaxPinSet); lcd.setCursor(0,1); lcd.print("YI"); lcd.setCursor(3,1); lcd.print(_YEncoderTicks); lcd.setCursor(10,1); lcd.print("YI"); lcd.setCursor(13,1); lcd.print(_YEncoderIndex); lcd.setCursor(18,1); lcd.print("Y"); lcd.setCursor(19,1); lcd.print("V" + _YMinPinSet); lcd.setCursor(17,1); lcd.print("^" + _YMaxPinSet); /* lcd.setCursor(15,0); lcd.print(_XCsens);*/ lcd.setCursor(3,3); lcd.print("<" + _XJoyLeft); lcd.setCursor(5,3); lcd.print(">" + _XJoyRight); lcd.setCursor(4,3); lcd.print("^" + _YJoyUp); lcd.setCursor(4,3); lcd.print("V" + _YJoyDown); delay(20); }
void connectOk() { debugf("connected"); WifiAccessPoint.enable(false); lcd.clear(); lcd.print("\7 "); lcd.print(WifiStation.getIP().toString()); // Restart main screen output procTimer.restart(); displayTimer.stop(); startWebClock(); // At first run we will download web server content if (!fileExist("index.html") || !fileExist("config.html") || !fileExist("api.html") || !fileExist("bootstrap.css.gz") || !fileExist("jquery.js.gz")) downloadContentFiles(); else startWebServer(); }
void close_box(){ lcd.clear(); lcd.print(F(" Locking box ")); Serial.println(F("Locking box")); // servo.attach(SERVO_PIN); digitalWrite(SERVO_ON_PIN, 1); delay(5000); servo.write(DOOR_CLOSED); delay(1000); // delay(5000); //servo.detach(); digitalWrite(SERVO_ON_PIN, 0); }
void connectFail() { debugf("connection FAILED"); WifiAccessPoint.config("MeteoConfig", "", AUTH_OPEN); WifiAccessPoint.enable(true); // Stop main screen output procTimer.stop(); displayTimer.stop(); lcd.clear(); lcd.setCursor(0,0); lcd.print("WiFi MeteoConfig"); lcd.setCursor(0,1); lcd.print(" "); lcd.print(WifiAccessPoint.getIP()); startWebServer(); WifiStation.waitConnection(connectOk); // Wait connection }
void init() { spiffs_mount(); Serial.begin(230400); // 115200 by default Serial.systemDebugOutput(false); // Enable debug output to serial Wire.begin(); lcd.begin(16,2); // initialize the lcd for(int i = 0; i< 3; i++) { lcd.backlight(); delay(150); lcd.noBacklight(); delay(250); } lcd.backlight(); lcd.setCursor(0,0); lcd.clear(); lcd.print(" Music Box "); lcd.setCursor(0,1); lcd.print(" Geek Labs "); SystemClock.setTimeZone(3); printTimer.initializeMs(1000*60, onPrintSystemTime).start(); Serial.begin(SERIAL_BAUD_RATE); // 115200 by default Serial.systemDebugOutput(true); // Enable debug output to serial WifiStation.enable(true); WifiStation.config(WIFI_SSID, WIFI_PWD); WifiAccessPoint.enable(false); Wire.beginTransmission(PT2258_ADDRESS); Wire.write(0xC0); Wire.endTransmission(); // Run our method when station was connected to AP WifiStation.waitConnection(connectOk, 30, connectFail); }
void screenPrinting() { lcd.clear(); if(screenPage < screenPages - 1) if(digitalRead(rightButtonPin)==LOW) screenPage++; if(screenPage > 0) if(digitalRead(leftButtonPin)==LOW) screenPage--; switch(screenPage) { case 0: overviewPage(); break; case 1: lcd.print("Status Wi-Fi:"); lcd.setCursor(0, 1); if(!networkManager.isConnected()) { if(digitalRead(selectButtonPin) == LOW) { lcd.print("Laczenie..."); lcd.print(networkManager.wifiConnect("Livebox-C28B", "lubieplacki11")); delay(10000); } else lcd.print("Brak polaczenia."); } else lcd.print("Polaczono z siecia!"); break; case 2: altitudeSet(); break; } }
void setLcd(int line, String text){ lcd.clear(); lcd.setCursor(0,line); lcd.print(text); }
void LcdClear() { lcd27.clear(); lcd3E.clear(); }
void setSoilHumidity() { lcd.clear(); lcd.print("Soil moisture"); lcd.setCursor(0, 1); lcd.print("Soil moisture"); }
bool navigationCheckDestination() { //Only process line following if navigation destination is known if ( currentNavigationDestination < 0 ) { lcd.clear(); lcd.print( "Where am I going?" ); lcdSelectDestination(); #ifdef AUTO_RETURN_HOME unsigned long navigationDestinationPromptTime = millis(); #endif while ( digitalRead(LCD_UP_PIN) == HIGH || digitalRead(LCD_DOWN_PIN) == HIGH || digitalRead(LCD_PLAY_PIN) == HIGH || digitalRead(LCD_STOP_PIN) == HIGH ) { #ifdef AUTO_RETURN_HOME if ( currentNavigationLocation != currentNavigationHome && navigationDestinationPromptTime + navigationReturnHomeTimeout * 1000ul < millis() ) { //Timeout has occured.. we are going to return home lcd.setCursor(0, 1); lcd.print( navigationReturnHomeTimeout ); lcd.print( " second timeout." ); navigationReturnHome(); break; } #endif if ( digitalRead(LCD_UP_PIN) == LOW ) { navigationSounds->play( soundUp ); if ( --lcdCurrentSelection < 0 ) lcdCurrentSelection = MAP_LOCATION_COUNT - 1; break; } if ( digitalRead(LCD_DOWN_PIN) == LOW ) { navigationSounds->play( soundDown ); if ( ++lcdCurrentSelection == MAP_LOCATION_COUNT ) lcdCurrentSelection = 0; break; } if ( digitalRead(LCD_PLAY_PIN) == LOW ) { if ( lcdCurrentSelection != currentNavigationLocation ) { navigationSounds->play( soundUhoh ); currentNavigationDestination = lcdCurrentSelection; /* Serial.print( "Current Destination: " ); Serial.print( currentNavigationDestination ); Serial.print( ": " ); Serial.println( destinationList[currentNavigationDestination] ); */ lcd.clear(); lcd.print( "Traveling from:" ); lcd.setCursor(0, 1); lcd.print( destinationList[currentNavigationLocation] ); lcd.setCursor(0, 2); lcd.print( "to:" ); lcd.setCursor(0, 3); lcd.print( destinationList[currentNavigationDestination] ); delay(1000); break; } else { navigationSounds->play( soundOhh ); } } if ( navigationCheckEStop() ) { navigationSounds->play( soundButtonPushed ); currentNavigationLocation = -1; //Returning to previous question return false; } } return false; } return true; }
int WiFiCmdRobot::WiFiCmdRobot_main() { String stringRead; int conx = 0; unsigned long timeout = 5; // 5s unsigned long start = 0; int ret=SUCCESS; // not specifically needed, we could go right to AVAILABLECLIENT // but this is a nice way to print to the serial monitor that we are // actively listening. // Remember, this can have non-fatal falures, so check the status while (1) { if(tcpServer.isListening(&status)) { Serial.print("Listening on port: "); Serial.println(portServer, DEC); digitalWrite(Led_Yellow, HIGH); // turn on led yellow break; } else if(DNETcK::isStatusAnError(status)) { Serial.println("Error Listening"); tcpClient.close(); tcpServer.close(); return -1; } } // wait for a connection until timeout conx = 0; start = millis(); while ((millis() - start < timeout*1000) && (conx == 0)) { if((count = tcpServer.availableClients()) > 0) { Serial.print("Got "); Serial.print(count, DEC); Serial.println(" clients pending"); conx = 1; // probably unneeded, but just to make sure we have // tcpClient in the "just constructed" state tcpClient.close(); } } // accept the client if((conx == 1) && (tcpServer.acceptClient(&tcpClient))) { Serial.println("Got a Connection"); lcd.clear(); lcd.print("Got a Connection"); stringRead = ""; while (tcpClient.isConnected()) { if (tcpClient.available()) { char c = tcpClient.readByte(); if (c == '\n') { Serial.println (stringRead); if (stringRead.startsWith("GET")) { Serial.println("GET"); ret = Cmd (stringRead); if (ret == SUCCESS) { ret = ReplyOK (); } else { cmd_GO[0] = 0; //reset GO command ret = ReplyKO (); } break; } else if (stringRead.startsWith("\r")) { // empty line => end Serial.println("empty line => end"); break; } else { // no GET Serial.println("no GET => ignore"); } stringRead = ""; } else { stringRead += c; } } } // end while } else if((cmd_GO[0] == CMD_GO) && (cmd_GO[1] > t_GO+(uint16_t)timeout)) // GO ongoing { Serial.println("Continue command GO"); cmd_GO[1] = cmd_GO[1] - t_GO - (uint16_t)timeout; cmd[0] = cmd_GO[0]; cmd[1] = t_GO; cmd[2] = cmd_GO[2]; ret = CmdRobot (cmd, resp, &resp_len); Serial.print("Call CmdRobot, ret: "); Serial.print(ret); Serial.print(" / resp_len: "); Serial.println(resp_len); } else if(cmd_GO[0] == CMD_GO) // end GO { Serial.println("End command GO"); cmd_GO[0] = 0; //reset GO command cmd[0] = CMD_STOP; // Stop after GO cmd[1] = 0; cmd[2] = 0; ret = CmdRobot (cmd, resp, &resp_len); Serial.print("Call CmdRobot, ret: "); Serial.print(ret); Serial.print(" / resp_len: "); Serial.println(resp_len); } // Close tcpClient.close(); digitalWrite(Led_Yellow, LOW); // turn off led yellow Serial.println("Closing TcpClient"); return SUCCESS; }
int WiFiCmdRobot::WiFiCmdRobot_begin() { int conID = DWIFIcK::INVALID_CONNECTION_ID; int cNetworks = 0; int iNetwork = 0; int ret=SUCCESS; Serial.println("Begin WiFiCmdRobot Init"); // initialize the SD-Card ret = initSDCard(); if (ret != SUCCESS) { Serial.print("Error Init SD-Card, error: "); Serial.println(ret); } else { Serial.println("Init SD-Card OK"); Serial.println(""); } // get infos from SD-Card ret=infoSDCard(); if (ret != SUCCESS) { Serial.print("Error Infos SD-Card, error: "); Serial.println(ret); } Serial.println("Begin WIFI Init"); lcd.clear(); lcd.print("Begin WIFI Init"); // set my default wait time to nothing DNETcK::setDefaultBlockTime(DNETcK::msImmediate); // start a scan DWIFIcK::beginScan(); while (1) { // every pass through loop(), keep the stack alive DNETcK::periodicTasks(); if(DWIFIcK::isScanDone(&cNetworks, &status)) { Serial.println("Scan Done"); break; } else if(DNETcK::isStatusAnError(status)) { Serial.print("Scan Failed"); return -1; } } while (1) { // every pass through loop(), keep the stack alive DNETcK::periodicTasks(); if(iNetwork < cNetworks) { DWIFIcK::SCANINFO scanInfo; int j = 0; if(DWIFIcK::getScanInfo(iNetwork, &scanInfo)) { Serial.print("Scan info for index: "); Serial.println(iNetwork, DEC); Serial.print("SSID: "); Serial.println(scanInfo.szSsid); Serial.print("Secuity type: "); Serial.println(scanInfo.securityType, DEC); switch(scanInfo.securityType) { case DWIFIcK::WF_SECURITY_OPEN: Serial.println("SECURITY OPEN"); break; case DWIFIcK::WF_SECURITY_WEP_40: Serial.println("WF SECURITY WEP 40"); break; case DWIFIcK::WF_SECURITY_WEP_104: Serial.println("SECURITY WEP 104"); break; case DWIFIcK::WF_SECURITY_WPA_WITH_KEY: Serial.println("SECURITY WPA WITH KEY"); break; case DWIFIcK::WF_SECURITY_WPA_WITH_PASS_PHRASE: Serial.println("SECURITY WPA WITH PASS PHRASE"); break; case DWIFIcK::WF_SECURITY_WPA2_WITH_KEY: Serial.println("SECURITY WPA2 WITH KEY"); break; case DWIFIcK::WF_SECURITY_WPA2_WITH_PASS_PHRASE: Serial.println("SECURITY WPA2 WITH PASS PHRASE"); break; case DWIFIcK::WF_SECURITY_WPA_AUTO_WITH_KEY: Serial.println("SECURITY WPA AUTO WITH KEY"); break; case DWIFIcK::WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE: Serial.println("SECURITY WPA AUTO WITH PASS PHRASE"); break; } Serial.print("Channel: "); Serial.println(scanInfo.channel, DEC); Serial.print("Signal Strength: "); Serial.println(scanInfo.signalStrength, DEC); Serial.print("Count of supported bit rates: "); Serial.println(scanInfo.cBasicRates, DEC); for( j= 0; j< scanInfo.cBasicRates; j++) { Serial.print("\tSupported Rate: "); Serial.print(scanInfo.basicRates[j], DEC); Serial.println(" bps"); } Serial.print("SSID MAC: "); for(j=0; j<sizeof(scanInfo.ssidMAC); j++) { if(scanInfo.ssidMAC[j] < 16) { Serial.print(0, HEX); } Serial.print(scanInfo.ssidMAC[j], HEX); } Serial.print("\nBeacon Period: "); Serial.println(scanInfo.beconPeriod, DEC); Serial.print("dtimPeriod: "); Serial.println(scanInfo.dtimPeriod, DEC); Serial.print("atimWindow: "); Serial.println(scanInfo.atimWindow, DEC); Serial.println(""); } else { Serial.print("Unable to get scan info for iNetwork: "); Serial.println(iNetwork, DEC); } iNetwork++; } else { break; } } if((conID = WiFiConnectMacro()) != DWIFIcK::INVALID_CONNECTION_ID) { Serial.print("Connection Created, ConID = "); Serial.println(conID, DEC); } else { Serial.print("Unable to connection, status: "); Serial.println(status, DEC); return -2; } while (1) { // every pass through loop(), keep the stack alive DNETcK::periodicTasks(); // initialize the stack with a static IP DNETcK::begin(ipServer); if(DNETcK::isInitialized(&status)) { Serial.println("IP Stack Initialized"); break; } else if(DNETcK::isStatusAnError(status)) { Serial.print("Error in initializing, status: "); Serial.println(status, DEC); return -3; } } Serial.println(""); IPv4 ip; DNETcK::getMyIP(&ip); Serial.print("My "); printIP(ip); Serial.println(""); DNETcK::getGateway(&ip); Serial.print("Gateway "); printIP(ip); Serial.println(""); DNETcK::getSubnetMask(&ip); Serial.print("Subnet mask: "); printNumb(ip.rgbIP, 4, '.'); Serial.println(""); DNETcK::getDns1(&ip); Serial.print("Dns1 "); printIP(ip); Serial.println(""); DNETcK::getDns2(&ip); Serial.print("Dns2 "); printIP(ip); Serial.println(""); DWIFIcK::CONFIGINFO configInfo; if(DWIFIcK::getConfigInfo(&configInfo)) { Serial.println("WiFi config information"); Serial.print("Scan Type: "); switch(configInfo.scanType) { case DWIFIcK::WF_ACTIVE_SCAN: Serial.println("ACTIVE SCAN"); break; case DWIFIcK::WF_PASSIVE_SCAN: Serial.println("PASSIVE SCAN"); break; } Serial.print("Beacon Timeout: "); Serial.println(configInfo.beaconTimeout, DEC); Serial.print("Connect Retry Count: "); Serial.println(configInfo.connectRetryCount, DEC); Serial.print("Scan Count: "); Serial.println(configInfo.scanCount, DEC); Serial.print("Minimum Signal Strength: "); Serial.println(configInfo.minSignalStrength, DEC); Serial.print("Minimum Channel Time: "); Serial.println(configInfo.minChannelTime, DEC); Serial.print("Maximum Channel Time: "); Serial.println(configInfo.maxChannelTime, DEC); Serial.print("Probe Delay: "); Serial.println(configInfo.probeDelay, DEC); Serial.print("Polling Interval: "); Serial.println(configInfo.pollingInterval, DEC); } else { Serial.println("Unable to get WiFi config data"); return -4; } tcpServer.startListening(portServer); lcd.setCursor(0,1); lcd.print("End WIFI Init"); Serial.println(""); Serial.println("End WiFiCmdRobot Init"); Serial.println("*********************"); Serial.println(""); return SUCCESS; }
int robot_begin() { int ret = SUCCESS; int ivalue = 0; ret = motor_begin(); if (ret != SUCCESS) return ret; Serial.println("Begin Robot Init"); Serial.println("****************"); lcd.clear(); lcd.print("Begin Robot Init"); pinMode(Led_Green, OUTPUT); // set the pin as output blink(Led_Green); pinMode(Led_Red, OUTPUT); // set the pin as output blink(Led_Red); pinMode(Led_Blue, OUTPUT); // set the pin as output blink(Led_Blue); Serial.println("Init Leds OK"); // initialize the buzzer pinMode(buzzPin, OUTPUT); buzz(3); Serial.println("Init Buzzer OK"); // initialize the Tilt&Pan servos TiltPan_begin(HSERVO_Pin, VSERVO_Pin); Serial.println("Init Tilt&Pan servos OK"); // initialize the camera Serial.println(" "); Serial.println("Begin Init Camera..."); ret=JPEGCamera.begin(); if (ret != SUCCESS) { Serial.print("Error Init Camera, error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("Init Camera KO "); } else { Serial.println("Init Camera OK"); lcd.setCursor(0,1); lcd.print("Init Camera OK "); } delay(5*1000);lcd.clear(); // initialize the SD-Card ret = initSDCard(); if (ret != SUCCESS) { Serial.print("Error Init SD-Card, error: "); Serial.println(ret); lcd.print("Init SD-Card KO "); } else { Serial.println("Init SD-Card OK"); lcd.print("Init SD-Card OK "); } // get infos from SD-Card ret=infoSDCard(); if (ret < 0) { Serial.print("Error Infos SD-Card, error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("Err Infos SDCard"); } else { no_picture = ret+1; Serial.print("no_picture starts at: "); Serial.println(no_picture); lcd.setCursor(0,1); lcd.print("Num picture:");lcd.print(no_picture); } delay(5*1000);lcd.clear(); // initialize the brightness sensor TEMT6000.TEMT6000_init(TEMT6000_Pin); // initialize the pin connected to the sensor Serial.println("Init Brightness sensor OK"); ivalue = TEMT6000.TEMT6000_getLight(); Serial.print("Value between 0 (dark) and 1023 (bright): "); Serial.println(ivalue); lcd.print("Lux:");lcd.print(ivalue);lcd.printByte(lcd_pipe); // initialize the temperature sensor TMP102.TMP102_init(); Serial.println("Init Temperature sensor OK"); double temperature = TMP102.TMP102_read(); ivalue = (int)(100.0 * temperature); Serial.print("Temperature: "); Serial.println(ivalue); lcd.print("T:");lcd.print(ivalue);lcd.printByte(lcd_celcius);lcd.printByte(lcd_pipe); // initialize the electret micro //Micro.Micro_init(MICRO_Pin); // initialize the pin connected to the micro //Serial.println("Init Micro OK"); // initialize the motion sensor pinMode(MOTION_PIN, INPUT); Serial.println("Init Motion sensor OK"); // initialize the IOT Serial 1 IOTSerial.IOTSbegin(1); // initialize the IOT Serial 1 to communicate with IOT WIFClient ESP8266 Serial.println ("Init IOT Serial 1 to communicate with IOT WIFClient ESP8266 OK"); // initialize the IOT Serial 2, interrupt setting IOTSerial.IOTSbegin(2); // initialize the IOT Serial 2 to communicate with IOT WIFServer ESP8266 Serial.println ("Init IOT Serial 2 to communicate with IOT WIFServer ESP8266 OK"); pinMode(IOT_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(IOT_PIN), IntrIOT, RISING); // set IOT interrupt interrupts(); // enable all interrupts Serial.print("Init Interrupts OK, IntIOT: "); Serial.println(IntIOT); lcd.setCursor(0,1); lcd.print("End Robot Init"); delay(5*1000);lcd.clear(); Serial.println("End Robot Init"); Serial.println("**************"); Serial.println(""); return SUCCESS; }
int robot_command (uint16_t *cmd, uint16_t *resp, uint8_t *resplen) { unsigned long start = 0; uint8_t infolen = 0; int checkdir; int motor_state_save; int error = -1; int ret = SUCCESS; lcd.clear(); // clear LCD reset_leds(); // turn off all leds digitalWrite(Led_Blue, HIGH); // turn on led blue switch (cmd[0]) { case CMD_STOP: Serial.println("CMD_STOP"); lcd.print("STOP"); stop(); motor_state = STATE_STOP; *resplen = 0; break; case CMD_START: if (cmd[1] == 0) { Serial.println("CMD_START"); lcd.print("START"); start_forward(); } else { Serial.print("CMD_START_TEST motor: "); Serial.println((int)cmd[1]); lcd.print("START motor: "); lcd.print((int)cmd[1]); start_forward_test(cmd[1]); } motor_state = STATE_GO; *resplen = 0; break; case CMD_CHECK_AROUND: Serial.println("CMD_CHECK_AROUND"); lcd.print("CHECK AROUND"); checkdir = check_around(); lcd.setCursor(0,1); if (checkdir == DIRECTION_LEFT) lcd.print("LEFT"); else if (checkdir == DIRECTION_RIGHT) lcd.print("RIGHT"); else if (checkdir == OBSTACLE_LEFT) lcd.print("OBSTACLE LEFT"); else if (checkdir == OBSTACLE_RIGHT) lcd.print("OBSTACLE RIGHT"); else if (checkdir == OBSTACLE) lcd.print("OBSTACLE"); else lcd.print("?"); resp[0] = checkdir; *resplen = 0+1; break; case CMD_MOVE_TILT_PAN: Serial.print("CMD_MOVE_TILT_PAN: "); Serial.print((int)cmd[1]);Serial.print((int)cmd[2]);Serial.print((int)cmd[3]);Serial.println((int)cmd[4]); if (cmd[2] == 0) HPos = (int)cmd[1] + 90; else HPos = 90 - (int)cmd[1]; if (cmd[4] == 0) VPos = (int)cmd[3] + 90; else VPos = 90 - (int)cmd[3]; Serial.print("CMD_MOVE_TILT_PAN, HPos VPos: "); Serial.print(HPos);Serial.println(VPos); lcd.print("MOVE TILT&PAN"); lcd.setCursor(0,1); lcd.print("X: "); lcd.print(HPos); lcd.print(" Y: "); lcd.print(VPos); TiltPan_move(HPos, VPos); *resplen = 0; break; case CMD_TURN: if (cmd[1] == 180) { Serial.print("CMD_TURN_BACK"); lcd.print("TURN BACK "); ret = turnback (10); // 10s max if (ret != SUCCESS){ Serial.print("turnback error"); Serial.println(ret); lcd.setCursor(0,1); lcd.print("turnback error: "); lcd.print(ret); error = 1; } } else if (motor_state == STATE_GO) { Serial.print("CMD_TURN, alpha: "); Serial.print((cmd[2] != 1) ? ('+'):('-')); Serial.println((int)cmd[1]); lcd.print("TURN"); lcd.print((cmd[2] != 1) ? ('+'):('-')); lcd.print((int)cmd[1]);lcd.print((char)223); //degree ret = turn ((double)((cmd[2] != 1) ? (cmd[1]):(-cmd[1])), 5); // 5s max if (ret != SUCCESS){ Serial.print("turn error"); Serial.println(ret); lcd.setCursor(0,1); lcd.print(" turn error: "); lcd.print(ret); error = 1; } } *resplen = 0; break; case CMD_INFOS: Serial.println("CMD_INFOS"); ret = infos (resp, &infolen); if (resp[MOTOR_STATE] == STATE_GO) { lcd.print("RUNING"); } else { lcd.print("STOPPED"); } lcd.setCursor(0,1); lcd.print((int)resp[TEMPERATURE]); lcd.print((byte)lcd_celcius);lcd.write(lcd_pipe); lcd.print((int)resp[DISTANCE]); lcd.print("cm");lcd.write(lcd_pipe); lcd.print((int)resp[DIRECTION]); lcd.print((char)223); //degree *resplen = infolen; break; case CMD_PICTURE: Serial.print("CMD_PICTURE, no_picture: "); no_picture++; Serial.println(no_picture); lcd.print("PICTURE "); motor_state_save = motor_state; if (motor_state == STATE_GO) { Serial.println("Stop"); stop(); motor_state = STATE_STOP; } ret = JPEGCamera.makePicture (no_picture); if (ret == SUCCESS) { lcd.setCursor(0,1); lcd.print("picture: "); lcd.print(no_picture); } else { Serial.print("makePicture error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); error = 1; } if (motor_state_save == STATE_GO) { Serial.println("Start"); start_forward(); motor_state = STATE_GO; } // byte 0: picture number resp[0] = no_picture; *resplen = 0+1; break; case CMD_ALERT: Serial.println("CMD_ALERT"); lcd.print("Alert"); blink(Led_Blue); buzz(5); // If motor_state == STATE_GO => Stop if (motor_state == STATE_GO) { Serial.println("Stop"); stop(); motor_state = STATE_STOP; } // Make 3 pictures left, front and right if ((HPos != 90) || (VPos !=90)) { HPos = 90; VPos = 90; TiltPan_move(HPos, VPos); } Serial.print("makePicture, no_picture: "); no_picture++; Serial.println(no_picture); lcd.print("PICTURE "); ret = JPEGCamera.makePicture (no_picture); if (ret == SUCCESS) { lcd.setCursor(0,1); lcd.print("picture: "); lcd.print(no_picture); } else { Serial.print("makePicture error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); error = 1; } if (ret == SUCCESS) { HPos = 0; VPos = 90; TiltPan_move(HPos, VPos); Serial.print("makePicture, no_picture: "); no_picture++; Serial.println(no_picture); lcd.print("PICTURE "); ret = JPEGCamera.makePicture (no_picture); lcd.setCursor(0,1); lcd.print("picture: "); lcd.print(no_picture); } else { Serial.print("makePicture error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); error = 1; } if (ret == SUCCESS) { HPos = 180; VPos = 90; TiltPan_move(HPos, VPos); Serial.print("makePicture, no_picture: "); no_picture++; Serial.println(no_picture); lcd.print("PICTURE "); ret = JPEGCamera.makePicture (no_picture); lcd.setCursor(0,1); lcd.print("picture: "); lcd.print(no_picture); } else { Serial.print("makePicture error: "); Serial.println(ret); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); error = 1; } // byte 0: last picture number resp[0] = no_picture; *resplen = 0+1; HPos = 90; VPos = 90; TiltPan_move(HPos, VPos); break; case CMD_CHECK: Serial.println("CMD_CHECK"); lcd.print("Check"); alert_status = check(); if (alert_status != SUCCESS) { Serial.print("Alert detected: ");Serial.println(alert_status); lcd.setCursor(0,1); lcd.print("Alert: "); lcd.print(alert_status); } else { Serial.print("No alert detected: "); lcd.setCursor(0,1); lcd.print(" No Alert"); } // byte 0: alert resp[0] = alert_status; *resplen = 0+1; break; case CMD_GO: Serial.print("CMD_GO, nb seconds: "); Serial.print((int)cmd[1]); lcd.print("GO ");lcd.print((int)cmd[1]);lcd.print("secs"); if (motor_state != STATE_GO) { Serial.println("start_forward"); start_forward(); motor_state = STATE_GO; } error = -1; GOtimeout = (unsigned long)cmd[1]; start = millis(); while((millis() - start < GOtimeout*1000) && (error == -1)) { ret = go(GOtimeout); if ((ret != SUCCESS) && (ret != OBSTACLE) && (ret != OBSTACLE_LEFT) && (ret != OBSTACLE_RIGHT)) { stop(); motor_state = STATE_STOP; error = 1; Serial.print("CMD_GO error: "); Serial.println(ret); Serial.println("Stop"); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); } else if ((ret == OBSTACLE) || (ret == OBSTACLE_LEFT) || (ret == OBSTACLE_RIGHT)) { stop(); motor_state = STATE_STOP; buzz(3); blink(Led_Red); Serial.print("CMD_GO Obstacle: ");Serial.println(ret); Serial.println("Stop"); lcd.setCursor(0,1); if (ret == OBSTACLE_LEFT) lcd.print("OBSTACLE LEFT"); else if (ret == OBSTACLE_RIGHT) lcd.print("OBSTACLE RIGHT"); else if (ret == OBSTACLE) lcd.print("OBSTACLE"); else ret = SUCCESS; checkdir = check_around(); Serial.print("check_around, direction: "); Serial.println(checkdir); lcd.clear(); lcd.print("check around"); lcd.setCursor(0,1); if (checkdir == DIRECTION_LEFT) lcd.print("LEFT"); else if (checkdir == DIRECTION_RIGHT) lcd.print("RIGHT"); else if (checkdir == OBSTACLE_LEFT) lcd.print("OBSTACLE LEFT"); else if (checkdir == OBSTACLE_RIGHT) lcd.print("OBSTACLE RIGHT"); else if (checkdir == OBSTACLE) lcd.print("OBSTACLE"); else lcd.print("?");; if (checkdir == DIRECTION_LEFT) { start_forward(); motor_state = STATE_GO; ret = turn (-45, 5); // turn -45 degrees during 5s max if (ret != SUCCESS) { stop(); motor_state = STATE_STOP; error = 1; Serial.print("turn error: "); Serial.println(ret); Serial.println("Stop"); lcd.clear(); lcd.print("turn left"); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); } else { lcd.clear(); lcd.print("turn left OK"); } } else if (checkdir == DIRECTION_RIGHT) { start_forward(); motor_state = STATE_GO; ret = turn (+45, 5); // turn +45 degrees during 5s max if (ret != SUCCESS) { stop(); motor_state = STATE_STOP; error = 1; Serial.print("turn error: "); Serial.println(ret); Serial.println("Stop"); lcd.clear(); lcd.print("turn right"); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); } else { lcd.clear(); lcd.print("turn right OK"); } } else { buzz(3); blink(Led_Red); motor_state = STATE_GO; ret = turnback (10); // turn back during 10s max if (ret != SUCCESS) { stop(); motor_state = STATE_STOP; error = 1; Serial.print("turnback error"); Serial.println(ret); Serial.println("Stop"); lcd.clear(); lcd.print("turnback"); lcd.setCursor(0,1); lcd.print("error: "); lcd.print(ret); } else { lcd.clear(); lcd.print("turnback OK"); } } } else { Serial.println("GO OK"); lcd.clear(); lcd.print("GO OK"); error = 0; } } // end while ret = infos (resp, &infolen); if (error == 0) { if (resp[MOTOR_STATE] == STATE_GO) { lcd.print("RUNNING"); } else { lcd.print("STOPPED"); } lcd.setCursor(0,1); lcd.print((int)resp[TEMPERATURE]); lcd.print((byte)lcd_celcius);lcd.write(lcd_pipe); lcd.print((int)resp[DISTANCE]); lcd.print("cm");lcd.write(lcd_pipe); lcd.print((int)resp[DIRECTION]); lcd.print((char)223); //degree } *resplen = infolen; break; case CMD_PI: Serial.print("CMD_PI activated, type: "); Serial.print((int)cmd[1]); Serial.print(" - freq: ");Serial.println((int)cmd[2]); lcd.print("PI activated ");lcd.print((int)cmd[1]); PI_activated = (int)cmd[1]; if (PI_activated <> PI_NO_COMM) PI_freqInfos = (int)cmd[2]* 1000; Serial.print("PI_activated: "); Serial.println(PI_activated); Serial.print("PI_freqInfos: ");Serial.println(PI_freqInfos); *resplen = 0; break; default: Serial.println("invalid command"); lcd.print("invalid command"); *resplen = 0; break; } //end switch if (error == 1) { blink(Led_Red); blink(Led_Red); buzz(7); *resplen = 0; } reset_leds(); // turn off all leds return ret; }
void computeKeypadInput(char key) { static uint8_t index = 0; static time_t modifiedTime; if (fsm.isInState(_waitState)) { switch (key) { case '#': lcd.clear(); fsm.transitionTo(_menuState); break; } } if (fsm.isInState(_menuState)) { switch (key) { case '#': lcd.clear(); fsm.transitionTo(_waitState); break; case '*': lcd.clear(); // We have to call an empty state or the menuState function // will not be called fsm.immediateTransitionTo(_emptyState); fsm.transitionTo(_menuState); break; case '1': lcd.clear(); fsm.transitionTo(_changeHourState); break; case '2': lcd.clear(); fsm.transitionTo(_changeStartLedState); break; case '3': lcd.clear(); fsm.transitionTo(_changeStopLedState); break; } } if (fsm.isInState(_changeHourState) or fsm.isInState(_changeStartLedState) or fsm.isInState(_changeStopLedState) or fsm.isInState(_changeFadeInState) or fsm.isInState(_changeFadeOutState)) { switch (key) { case '*': if (index != 6) { break; } index = 0; lcd.clear(); if (fsm.isInState(_changeHourState)) { RTC.set(modifiedTime); setSyncProvider(RTC.get); fsm.transitionTo(_waitState); } else if (fsm.isInState(_changeStartLedState)) { led.setStartTime(modifiedTime); led.saveEepromDatas(); fsm.transitionTo(_changeFadeInState); } else if (fsm.isInState(_changeStopLedState)) { led.setStopTime(modifiedTime); led.saveEepromDatas(); fsm.transitionTo(_changeFadeOutState); } else if (fsm.isInState(_changeFadeInState)) { led.setFadeInTime(modifiedTime); led.saveEepromDatas(); fsm.transitionTo(_waitState); } else if (fsm.isInState(_changeFadeOutState)) { led.setFadeOutTime(modifiedTime); led.saveEepromDatas(); fsm.transitionTo(_waitState); } break; case '#': index = 0; lcd.clear(); fsm.transitionTo(_waitState); break; default: modifiedTime = computeUserInput(index, atoi(&key)); index++; break; } } }
void secret_button() { static unsigned long but1; but1 = millis(); Serial.println(F("1")); while(!digitalRead(ON_PIN)){ delay(20); if (millis() > but1 + 5000){ go_sleep(); } } but1 = millis(); while(millis() < but1 + BUTTON1_DELAY){delay(20); if(!digitalRead(ON_PIN)){ Serial.println(F("2")); while(!digitalRead(ON_PIN)){delay(20);} but1 = millis(); while(millis() < but1 + BUTTON1_DELAY){delay(20); if(!digitalRead(ON_PIN)){ Serial.println(F("3")); while(!digitalRead(ON_PIN)){delay(20);} but1 = millis(); while(millis() < but1 + BUTTON1_DELAY){delay(20); if(!digitalRead(ON_PIN)){ Serial.println(F("4")); while(!digitalRead(ON_PIN)){delay(20);} but1 = millis(); while(millis() < but1 + BUTTON1_DELAY){delay(20); if(!digitalRead(ON_PIN)){ Serial.println(F("5")); but1 = millis(); while(!digitalRead(ON_PIN)){delay(20); Serial.println(F("6")); if(millis() > but1 + 800){ Serial.println(F("Release now!")); lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("Release now!")); delay(500); lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("Press: open box")); lcd.setCursor(0,1); lcd.print(F("Hold: reset game")); delay(1000); while(digitalRead(ON_PIN)){} but1 = millis(); while(!digitalRead(ON_PIN)){delay(20);} if(millis() - but1 > 1000){ lcd.clear(); lcd.print(F("RESET GAME!")); delay(3000); target = 1; EEPROM.write(EEPROM_TARGET_INDEX, 1); break; } else { open_box(); delay(15000); close_box(); break; } } } } } } } } } } } }
// { SPECIAL FUNCTIONS ------------------------------------------------------- void setup(){ // Required if SYSTEM_MODE = SEMI_AUTOMATIC or MANUAL // if(Particle.connected() == false){ // Particle.connect(); // } pinMode(BOARD_LED, OUTPUT); //INPUT, INPUT_PULLUP, INPUT_PULLDOWN or OUTPUT // pinMode(DAC, OUTPUT); //INPUT, INPUT_PULLUP, INPUT_PULLDOWN or OUTPUT // pinMode( D6, INPUT ); // attachInterrupt( D6, on_d6, CHANGE, 13); // Note: do not set the pinMode() with analogRead(). The pinMode() is // automatically set to AN_INPUT the first time analogRead() is called // src: https://docs.particle.io/reference/firmware/photon/#analogread-adc- // In other words, don't do: pinMode(analog_pin, INPUT); // { Declare Cloud Variables/Functions/Events ---------------------------- // Up to 20 Variables Particle.variable("help", HELP); Particle.variable("a", PV_a); Particle.variable("b", PV_a); Particle.variable("c", PV_a); // Up to 15 Functions. Particle.function("do", PF_do); Particle.function("set", PF_set); #ifdef USE_STDIN Particle.function("stdin", PF_stdin); #endif // USE_STDIN // Up to 4 Event Subscriptions Particle.subscribe("all", PS_handler, MY_DEVICES); // For documentation specify what events you will publish: // Particle.publish("stdout", "...") // Particle.publish("stderr", "...") // } Declare Cloud Variables/Functions/Events ---------------------------- strcpy(PV_a, "Hello World"); #ifdef USE_LCD lcd.init(); lcd.backlight(); lcd.clear(); lcd.setCursor(0,1); lcd.print("Hello World"); #endif #ifdef USE_SERIAL0 Serial.begin(9600); #endif // USE_SERIAL0 #ifdef USE_SERIAL1 Serial1.begin(9600); #endif // USE_SERIAL1 #ifdef USE_TIMER_2SEC timer_2sec.start(); #endif // USE_TIMER_2SEC }
/** 0123456789012345 ��ʼ - Sample data... **DFRobot** - 20:00 -19.9C 99%RH 1005hPa - 31th-C A=-19.9C H=-19.9C L=-19.9C 31th-RH A=99% H=99% L=99% 31th-hPa A=1005 H=1005 L=1005 - 30th-C A=-19.9C H=-19.9C L=-19.9C 30th-RH A=99% H=99% L=99% 30th-hPa A=1005 H=1005 L=1005 TEMP(C) T or TEMP P or RH **/ void WeatherStation::displayNext() { uint8_t i; uint8_t dataType; uint8_t lcdCurrentRow; uint8_t date; int16_t data; uint8_t &days = displayMgt.days; uint8_t &measureIndex = displayMgt.measureIndex; bool &dateShowFlag = displayMgt.dateShowFlag; uint8_t &nowDataIndex = displayMgt.nowDataIndex; String &rowInfo = displayMgt.rowInfo; String unitWord; /**display current**/ DBG_PRINTLN_VAR(days,DEC); DBG_PRINTLN_VAR(nowDataIndex,DEC); DBG_PRINTLN_VAR(measureIndex,DEC); lcd.clear(); lcdCurrentRow = 0; /**display date**/ if ( !dateShowFlag ) { rowInfo = ""; rowInfo += currentYear; rowInfo += "/"; rowInfo += currentMonth; rowInfo += "/"; rowInfo += currentDate; rowInfo += " "; rowInfo += currentHour; rowInfo += ":"; rowInfo += currentMinute; lcd.setCursor( 0, lcdCurrentRow++ ); lcd.print( rowInfo ); rowInfo = " "; //one space before data dateShowFlag = true; } /**display current data**/ if ( dateShowFlag && (nowDataIndex < measureNum) ) { for ( i = nowDataIndex; i < measureNum; i++ ) { if ( false == a_measureData[i].valid ) { break; } dataType = a_measureData[i].dataType; data = a_measureData[i].p_sensor->getValue( dataType ); unitWord = a_measureData[i].p_sensor->formatValue( data, dataType ); if ( (rowInfo.length() + unitWord.length()) > LCD_COL_NUM ) { lcd.setCursor( 0, lcdCurrentRow++ ); lcd.print( rowInfo ); rowInfo = " "; if (lcdCurrentRow >= LCD_ROW_NUM) { break; } } rowInfo += unitWord; rowInfo += " "; } /*display the last row*/ if ( rowInfo.length() > 2 ) //valid str > 2 { lcd.setCursor( 0, lcdCurrentRow ); lcd.print( rowInfo ); rowInfo = ""; } nowDataIndex = i; return; } /**display previous statistic**/ if ( nowDataIndex >= measureNum ) { uint8_t number; Sensor *p_sensor; date = dataHouse.getDate(days); if ( date > 31 ) { clrDisplayMgt(); lcd.print( " ** no data **" ); } else { static int8_t strLeftIndex = 0; int8_t strRightIndex; if ( 0 == rowInfo.length()) { const char * dataName; uint8_t hour; rowInfo = ""; rowInfo += date; rowInfo +="th "; dataType = a_measureData[measureIndex].dataType; p_sensor = a_measureData[measureIndex].p_sensor; if ( NULL != p_sensor ) { dataName = p_sensor->getDataName(dataType); rowInfo += dataName; rowInfo += " "; data = dataHouse.getDayAverage( dataType, days, &number ); rowInfo += number; rowInfo += "data"; rowInfo += '\n'; if ( number > 0) { unitWord = p_sensor->formatValue( data, dataType ); rowInfo += " Avg:"; rowInfo += unitWord; rowInfo += '\n'; data = dataHouse.getDayMin( dataType, days, &hour ); unitWord = p_sensor->formatValue( data, dataType ); rowInfo += " "; rowInfo += unitWord; rowInfo += " "; rowInfo += hour; rowInfo += ":00"; rowInfo += "\n"; data = dataHouse.getDayMax( dataType, days, &hour ); unitWord = p_sensor->formatValue( data, dataType ); rowInfo += " "; rowInfo += unitWord; rowInfo += " "; rowInfo += hour; rowInfo += ":00"; rowInfo += "\n"; } } strLeftIndex = 0; } do { strRightIndex = rowInfo.indexOf('\n', strLeftIndex); if ( strRightIndex < 0 ) { break; } lcd.setCursor( 0, lcdCurrentRow++ ); lcd.print( rowInfo.substring( strLeftIndex, strRightIndex ) ); displayMgt.statisticFlag = true; strLeftIndex = (strRightIndex + 1); if ( lcdCurrentRow >= LCD_ROW_NUM ) { break; } }while(1); if ( ((strRightIndex + 1) >= rowInfo.length()) || (strRightIndex < 0) ) { rowInfo = ""; measureIndex++; if ( measureIndex >= measureNum ) { days++; measureIndex = 0; } if ( days >= DATA_SAVE_DAYS ) { clrDisplayMgt(); } } } } }
void loop() { //Serial.print(F("Free RAM1:")); Serial.println(freeRam()); // Check secret button but = !digitalRead(ON_PIN); if(but){ Serial.println(F("Button pressed")); secret_button(); } bool GPS_debug = 0; unsigned long t = millis(); while (ss.available() > 0 || t + 1100 < millis()){ gps.encode(ss.read()); GPS_debug = 1; } if (GPS_debug) { Serial.println(F("GPS received")); GPS_debug = 0; } sats_fix = gps.satellites.value(); hdop = gps.hdop.value(); position_lat = gps.location.lat(); position_lon = gps.location.lng(); //target = 3; // debug distance = gps.distanceBetween(position_lat, position_lon, target_lat[target], target_lon[target]); //distance = 4; // debug static int sim, ok; #ifdef SIMULATION if (but == 1){ sim = 1; delay (1000); } else { sim = 0; lcd.setCursor(14, 1); lcd.print(target); } if (distance > 30 && sim == 0){ #else if (distance > 30) { #endif lcd_target(lcd, target, distance, sats_fix); } else { #ifdef BUTTON_FOR_NEXT_STEP wait finish; finish.set_time(2500); finish.set_steps(2); lcd.setCursor(0, 0); if(finish.step() == 1){ lcd.print(F("You are at your ")); lcd.setCursor(0, 1); lcd.print(F("current target.")); } if (finish.step() == 2){ lcd.setCursor(0, 0); lcd.print(F("Press the button")); lcd.setCursor(0, 1); lcd.print(F("to continue... ")); } if (but == 1){ // Go to next target target++; ok = 1; } #else lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("You are at your ")); lcd.setCursor(0, 1); lcd.print(F("current target.")); target++; delay(5000); but = 0; #endif // Open the box at the end of game if(target > NUMBER_OF_TARGETS){ lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("CONRATULATIONS! ")); delay(5000); open_box(); } else { EEPROM.write(EEPROM_TARGET_INDEX, target); } } if(millis() > update_time + 1000){ update_time = millis(); Serial.println(gps.location.lat(), 6); Serial.print(F("LAT=")); Serial.println(gps.location.lat(), 6); Serial.print(F("LONG=")); Serial.println(gps.location.lng(), 6); Serial.print(F("ALT=")); Serial.println(gps.altitude.meters()); Serial.print(F("hdop=")); Serial.println(hdop); Serial.print(F("sats=")); Serial.println(sats_fix); if(hdop < 500 && sats_fix > 4){ fix = 1; distance = gps.distanceBetween(position_lat, position_lon, TARGET_1_LAT, TARGET_1_LON); } else{ fix = 0; strength = sats_fix; //lcd_gps_signal(lcd, strength); } } if(millis() > sleep_time + SLEEP_TIME_MS){ go_sleep(); } } void go_sleep(void) { lcd.clear(); lcd.print(F("Going to sleep..")); delay(2000); pinMode(ON_PIN, OUTPUT); digitalWrite(ON_PIN, 0); }