目标:
用四个5比索硬币触发LED;一旦掉落了4个5比索硬币,LED就会亮起来。
要求:
这是我迄今为止制作的节目:
const int sensor1 = A0;//input of sensor
const int ledRed = 9;// output pin of LED
int sensorValue;
int count=0;
void setup() {
Serial.begin(9600);
pinMode(ledRed, OUTPUT);
}
void loop() {
sensorValue = analogRead(sensor1); //stores the value of the ldr
if (sensorValue <= 200) {
while(count != 4) {
Serial.println("Please Input a Coin: ");
count++;
}
Serial.println("Machine Dispensing... ");
digitalWrite(ledRed, HIGH);
}
else {
digitalWrite(ledRed, LOW);
}
delay(2000);
}