Tuesday, October 6, 2009

Using Analog Reading + Implemented pseudo code - Tsveta

const int ledPin = 13;//declare pin 13
const int buttonPin = 2;// declare pin 2
int sensorPin = 4;// declare pin 4

void setup() {
pinMode(buttonPin, INPUT);//set pin 2 to be an input source
pinMode(sensorPin, INPUT);// set pin 4 to be an input source
pinMode(ledPin, OUTPUT);// set pin 13 to be an output source
}

void loop() {
int getstate = digitalRead(buttonPin); //read the state of the button pin and
//inputs the value into the variable getstate
int timereceived = analogRead(sensorPin);//reads analog data
if (getstate == HIGH){//if button is pressed
digitalWrite(ledPin, HIGH);//turn the LED on
delay(timereceived);//assigns the data read from the sensor input to the delay time
}
delay(timereceived / 100);//delay to remove noise
if (getstate == LOW){//if button is released
digitalWrite(ledPin, LOW);//turn the LED off
delay(timereceived);//assigns the data read from the sensor input to the delay time
}
}

No comments:

Post a Comment