Changes

User:S8brown

132 bytes added, 02:48, 12 June 2009
no edit summary
And Here's the code!
{{
int turn1 = 12; // choose the pins for controlling direction <br>
int turn2 = 13;<br>
int tilt1 = 4; // choose the input pin (for the tilt sensors)<br>
int tilt2 = 5;<br>
int val1 = 0; // variable for reading the pin status<br>
int val2 = 0;<br>
int turn1 = 12; // choose the pins for controlling direction <br> int turn2 = 13;<br> int tilt1 = 4; // choose the input pin (for the tilt sensors)<br> int tilt2 = 5;<br> int val1 = 0; // variable for reading the pin status<br> int val2 = 0;<br>  void setup() {<br> pinMode(turn1, OUTPUT); // declare turn pins as output<br> pinMode(turn2, OUTPUT);<br> pinMode(tilt1, INPUT); // declare tilt sensors as input<br> pinMode(tilt2, INPUT);<br>
digitalWrite(0,HIGH); // write a HIGH to allow for current to flow through pin<br> digitalWrite(1,HIGH);<br> }
void loop(){ val1 = digitalRead(tilt1); // read input value val2 = digitalRead(tilt2);
if (val1 == HIGH) { // if tilted, turn the motor! pinMode(turn1,OUTPUT); // turn the pins on pinMode(turn2,OUTPUT); digitalWrite(turn1, LOW); // turn the motor! digitalWrite(turn2, HIGH); } if (val2 == HIGH) { // if tilted, turn the motor! pinMode(turn1,OUTPUT); // turn the pins on pinMode(turn2,OUTPUT); digitalWrite(turn1, HIGH); // turn the motor the other way! digitalWrite(turn2, LOW); } if(val1 != HIGH && val2 != HIGH){ // if it's not tilted either way pinMode(turn1,INPUT); // turn the output pins "off" pinMode(turn2,INPUT); }
}}
[[User:S8brown/Project | Other Projects]]
30
edits