Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Arduino Demo Software
- Connect via either Arduino Serial Monitor or HyperTerminal
- and you can control your robot via the W.A.S.D. keys.
- Any other key will stop your robot in it's travels.
- This example code is in the public domain.
- */
- void setup(void){
- Serial.begin(9600);
- }
- void loop(void){
- while (Serial.available() < 1) {} // Wait until a character is received
- char val = Serial.read();
- switch(val){ // Perform an action depending on the command
- case 'w'://Move Forward
- forward();
- break;
- case 's'://Move Backwards
- reverse();
- break;
- case 'a'://Turn Left
- left();
- break;
- case 'd'://Turn Right
- right();
- break;
- default:
- halt();
- break;
- }
- }
- void forward() {
- Serial.println("Forward");
- analogWrite(11, 100);
- analogWrite(6, 100);
- }
- void reverse() {
- Serial.println("Reverse");
- analogWrite(10, 100);
- analogWrite(5, 100);
- }
- void halt() {
- Serial.println("Stopped");
- digitalWrite(11, LOW);
- digitalWrite(10, LOW);
- digitalWrite(6, LOW);
- digitalWrite(5, LOW);
- }
- void left() {
- Serial.println("Left");
- digitalWrite(10, HIGH);
- digitalWrite(6, HIGH);
- }
- void right() {
- Serial.println("Right");
- digitalWrite(11, HIGH);
- digitalWrite(5, HIGH);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement