Skip to content

Instantly share code, notes, and snippets.

@aaronsherwood
Created October 17, 2013 05:32
Show Gist options
  • Save aaronsherwood/7019570 to your computer and use it in GitHub Desktop.
Save aaronsherwood/7019570 to your computer and use it in GitHub Desktop.
int sensorPin = A0;
int buttonPin = 2;
int ledPin = 12;
int sensorValue = 0;
int buttonValue = 0;
int count = 0;
int target_wraps = 10;
bool check = true;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
sensorValue = analogRead(sensorPin);
buttonValue = digitalRead(buttonPin);
if (sensorValue > 900 && check == true) {
count++;
check=false;
}
if (sensorValue < 900) {
check=true;
}
if (buttonValue==1){
digitalWrite(ledPin, LOW);
count=0;
}
if (count>target_wraps-1) {
digitalWrite(ledPin, HIGH);
}
Serial.println(sensorValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment