Now plug your Arduino board to the PC and upload the following sketch.
int PIN_LED = 13; void setup() { pinMode(PIN_LED, OUTPUT); Serial.begin(9600); Serial.println("Welcome to ArduinoSerialControl"); Serial.println("Enter 't' to retrieve current millis"); Serial.println("Enter 'l' to toggle LED on pin 13"); } void loop() { int bytes=Serial.available(); if (bytes > 0) { char c = Serial.read(); switch (c) { case 't': // return the uptime in milliseconds Serial.print("millis="); Serial.println(millis()); break; case 'l': // toggle on-board led connected to pin 13 digitalWrite(PIN_LED, !digitalRead(PIN_LED)); Serial.print("LED status is "); Serial.println(digitalRead(PIN_LED)); break; } } }
Open the serial monitor and set the baud rate to 9600. Try sending commands using the serial console.
This is just an experiment. If you want to build a solid communication using Firmata protocol.
Complete Control Of An Arduino Via Serial
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.