From 0920918c3781fb63602fab2e5994423ca99b7faa Mon Sep 17 00:00:00 2001 From: Amira Abdel-Rahman <amiraa@mit.edu> Date: Sat, 10 Dec 2022 20:57:46 +0000 Subject: [PATCH] Upload New File --- .../htmaa_serial_arduinoA0withLED.ino | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Scripts by Iulian/htmaa_serial_arduinoA0withLED.ino diff --git a/Scripts by Iulian/htmaa_serial_arduinoA0withLED.ino b/Scripts by Iulian/htmaa_serial_arduinoA0withLED.ino new file mode 100644 index 0000000..97663bb --- /dev/null +++ b/Scripts by Iulian/htmaa_serial_arduinoA0withLED.ino @@ -0,0 +1,42 @@ +// Sends 3 numerical values to the serial port, and reads one numerical value (then turns onboard LED if that value is >0) + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + + pinMode(A0, INPUT); + pinMode(13, OUTPUT); +} + + +void loop() { + + // SEND TO COMPUTER 3 integer values separated by comma + + int data0 = analogRead(A0); + int data1 = 123; + int data2 = 456; + + Serial.print(data0); + Serial.print(","); + Serial.print(data1); + Serial.print(","); + Serial.print(data2); + Serial.println(); + + delay(100); // a bit of delay so the communication buffer doesn't get overloaded + + + // RECEIVE FROM COMPUTER a text value that gets converted into int + while (Serial.available()) { + String s = Serial.readStringUntil('\n'); + + // TURN ON LED if the value from computer is >0 + int x = s.toInt(); + if (x > 0) { + digitalWrite(13, HIGH); + } else { + digitalWrite(13, LOW); + } + } +} -- GitLab