Created
April 8, 2014 15:49
-
-
Save jerog1/10146309 to your computer and use it in GitHub Desktop.
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
// Code by Jeremy Nir 2014 | |
// Frankensteined together from Servo example and Digital Read examples on Arduino.cc | |
// short and sweet code that turns on a power bar when a coin is inserted | |
#include <Servo.h> | |
int servoPin = 9; | |
Servo servo; | |
//int angleON = 68; // servo flicks to it's left | |
//int angleOFF = 58; // servo flicks to it's right | |
// my constants | |
const int COINPin = 4; // pin that the coin sensor is attached to | |
const int COUNTPin = 3; // pin that the count sensor is attached to | |
const int ledPin = 13; // pin that the LED is attached to | |
const int threshold = 0; // an arbitrary threshold level that's in the range of the analog input | |
void setup() { | |
//add the servo | |
servo.attach(servoPin); | |
// initialize the LED pin as an output: | |
pinMode(ledPin, OUTPUT); | |
// initialize serial communications: | |
Serial.begin(9600); | |
} | |
void loop() { | |
// read the value of the potentiometer: | |
int digitalValue = digitalRead(COINPin); | |
// if the analog value is high enough, turn on the LED: | |
if (digitalValue > threshold) { | |
digitalWrite(ledPin, HIGH); | |
servo.write(75); // turns on the lights! | |
delay(35000); | |
} | |
else { | |
digitalWrite(ledPin,LOW); | |
servo.write(58); // and turns them off again | |
delay(30); | |
} | |
// print the analog value: | |
Serial.println(digitalValue); | |
delay(50); // delay in between reads for stability | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment