Last active
August 29, 2015 14:01
-
-
Save redroot/ab4de894d490a931cefe to your computer and use it in GitHub Desktop.
Arduino Dumping Ground
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
| int motorA = 3; | |
| int ldr = A0; | |
| int lightLimit = 48; // 45 is 'dark' for the LDR | |
| int motorValue = 130; | |
| // set voltage in power supply to 7.1, current fll (0.15k) | |
| void setup() | |
| { | |
| pinMode(ldr, INPUT); | |
| pinMode(motorA, OUTPUT); | |
| Serial.begin(9600); | |
| } | |
| void loop() | |
| { | |
| int ldrReading = analogRead(ldr); | |
| // press Shift + Cmd + M to see the reading | |
| Serial.println(ldrReading); | |
| if(ldrReading <= lightLimit){ | |
| analogWrite(motorA, motorValue); | |
| }else{ | |
| analogWrite(motorA, 0); | |
| } | |
| } |
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
| int motorA = 3; | |
| int pto = A0; | |
| int motorValue = 130; | |
| // set voltage in power supply to 7.1, current fll (0.15k) | |
| void setup() | |
| { | |
| pinMode(pto, OUTPUT); | |
| Serial.begin(9600); | |
| } | |
| void loop() | |
| { | |
| int reading = analogRead(pto); | |
| Serial.println(reading); | |
| if(reading > 40){ | |
| Serial.println("BIG VOLTAGE"); | |
| analogWrite(motorA, motorValue); | |
| }else if(reading > 9){ | |
| Serial.println("SMALL VOLTAGE"); | |
| analogWrite(motorA, motorValue / 2); | |
| }else{ | |
| Serial.println("NO VOLTAGE"); | |
| analogWrite(motorA, 0); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment