通过Arduino的硬币计数器和探测器:如何在触发LED之前通过投下4倍硬币来点亮LED?

时间:2014-11-30 04:42:13

标签: arduino

目标:

用四个5比索硬币触发LED;一旦掉落了4个5比索硬币,LED就会亮起来。

要求:

  • 柜台只应计算5比索硬币。
  • 一旦计数器的总数为4,LED就会亮起。
  • 柜台不会识别任何其他硬币,只有5比索。

这是我迄今为止制作的节目:

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);
}

0 个答案:

没有答案