/* * webSerial for testing javascript connection with an arduino * * Latest work at https://github.com/hpssjellis/webMLserial * * Note: On the Arduino Serial monitor make sure no line-ending or if statements will not work * * Android https://hpssjellis.github.io/web-serial-polyfill/index.html * Laptops Desktops https://hpssjellis.github.io/my-examples-of-arduino-webUSB-webSerial/public/index.html * IOS not really sure * */ #include // Only needed for https://platformio.org/ String readString; int myDelay = 200; // non-block delay in milliseconds unsigned long myStart; void setup() { Serial.begin(9600); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); // onboard LED, HIGH = off while (!Serial) {} // do nothing and wait myStart = millis(); // set delay randomSeed(analogRead(A0)); // AO pin on XIAO does not have to be connected to anything Serial.println("timestamp,accX,accY,accZ"); // CSV file heading titles } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(50); if ( (millis() - myStart ) >= myDelay) { myStart = millis(); // reset the delay time digitalWrite(LED_BUILTIN, LOW); Serial.println( String(myStart)+ "," + String(analogRead(A0)) + "," + String(analogRead(A1)) + "," + String(analogRead(A2)) ); delay(50); // make this smaller as needed } }