Created
October 11, 2017 16:06
-
-
Save alex4o/b98efa22ef6097b870a397f664bd1a52 to your computer and use it in GitHub Desktop.
Something something robot
This file contains 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
/* | |
Input Pullup Serial | |
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a | |
digital input on pin 2 and prints the results to the serial monitor. | |
The circuit: | |
* Momentary switch attached from pin 2 to ground | |
* Built-in LED on pin 13 | |
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal | |
20K-ohm resistor is pulled to 5V. This configuration causes the input to | |
read HIGH when the switch is open, and LOW when it is closed. | |
created 14 March 2012 | |
by Scott Fitzgerald | |
http://www.arduino.cc/en/Tutorial/InputPullupSerial | |
This example code is in the public domain | |
*/ | |
short forwardLeft = 5; | |
short reverseLeft = 6; | |
short forwardRight = 10; | |
short reverseRight = 11; | |
short sensorLeft = 1; | |
short sensorRight = 2; | |
void setup() { | |
//start serial connection | |
Serial.begin(9600); | |
//Initialise Sensor Input | |
pinMode(sensorLeft, INPUT); | |
pinMode(sensorRight, INPUT); | |
//Assign variable names to motor controls | |
pinMode(forwardLeft, OUTPUT); | |
pinMode(reverseLeft, OUTPUT); | |
pinMode(forwardRight, OUTPUT); | |
pinMode(reverseRight, OUTPUT); | |
// digitalWrite(forwardLeft, HIGH); | |
} | |
void loop() { | |
//Reads sensor value | |
int sensorRightVal = digitalRead(sensorRight); | |
int sensorLeftVal = digitalRead(sensorLeft); | |
if (sensorVal == 1){ | |
digitalWrite(forwardLeft, HIGH); | |
digitalWrite(forwardRight, HIGH); | |
} else { | |
digitalWrite(forwardLeft, LOW); | |
digitalWrite(forwardRight, LOW); | |
} | |
//print out the value of the pushbutton | |
Serial.print(sensorLeftVal); | |
Serial.println(sensorRightVal); | |
} | |
tPullupSerial | |
This example code is in the public domain | |
*/ | |
short forwardLeft = 5; | |
short reverseLeft = 6; | |
short forwardRight = 10; | |
short reverseRight = 11; | |
short sensorLeft = 1; | |
short sensorRight = 2; | |
void setup() { | |
//start serial connection | |
Serial.begin(9600); | |
//Initialise Sensor Input | |
pinMode(sensorLeft, INPUT); | |
pinMode(sensorRight, INPUT); | |
//Assign variable names to motor controls | |
pinMode(forwardLeft, OUTPUT); | |
pinMode(reverseLeft, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment