Created
December 5, 2014 00:34
-
-
Save goFrendiAsgard/6d7e900229894909d82e to your computer and use it in GitHub Desktop.
Arduino Push-Button & LED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Gunvarrel v 0.0.1 | |
| * Purpose: To emulate simple sonar robot | |
| * Description: Far from perfect. I use LED instead of motor, and push-button instead of sonar | |
| * Author: Go Frendi Gunawan | |
| */ | |
| int left_motor = 12; // left motor (now just LED) | |
| int right_motor = 13; // right motor (now just LED) | |
| int sonar_sensor = 8; // sonar (now just push-button) | |
| void setup(){ | |
| Serial.begin(9600); | |
| pinMode(left_motor, OUTPUT); | |
| pinMode(right_motor, OUTPUT); | |
| pinMode(sonar_sensor, INPUT ); | |
| } | |
| void straight(){ | |
| digitalWrite(left_motor, HIGH); | |
| digitalWrite(right_motor, HIGH); | |
| delay(100); | |
| } | |
| void turn(){ | |
| digitalWrite(left_motor, LOW); | |
| digitalWrite(right_motor, HIGH); | |
| delay(100); | |
| } | |
| void loop(){ | |
| int obstacle_detected = digitalRead(sonar_sensor); | |
| Serial.println(obstacle_detected); | |
| if(obstacle_detected == HIGH){ | |
| turn(); | |
| }else{ | |
| straight(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment