Skip to content

Instantly share code, notes, and snippets.

@jerog1
Created April 8, 2014 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerog1/10146309 to your computer and use it in GitHub Desktop.
Save jerog1/10146309 to your computer and use it in GitHub Desktop.
// 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