Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Console.h>
- #include <Servo.h>
- char ib;
- Servo servo1;
- void setup()
- {
- servo1.attach(6); // Attach servo to pin 7
- Bridge.begin(); // Initialize Bridge
- Console.begin(); // Initialize Console
- pinMode(3, OUTPUT); // tone
- }
- void loop() {
- if (Console.available() > 0)
- {
- ib = Console.read();
- if (ib == 'S') // if Byte is S
- {
- uint8_t b1 = Console.read (); //read next 3 numbers that come after S
- uint8_t b2 = Console.read ();
- uint8_t b3 = Console.read ();
- servo1.write((b1 - '0')*100 + (b2 - '0')*10 + b3 - '0'); //put them in the correct order
- }
- if (ib == 't') {
- uint8_t b1 = Console.read ();
- tone(3, (b1 - '0')*100, 200);
- } //ex: t8 gives tone 800 on pin 3 for 200 ms
- if (ib == 'T') {
- uint8_t b1 = Console.read ();
- tone(3, (b1 - '0')*1000, 200);
- } //ex: gives tone 8000 on pin 3 for 200 ms
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement