Program:
/*
Amar Lakar Cengkal
diy ALC
*/
#define ten_sens 8
#define twenty_sens 9
#define fifty_sens 10
//initialization
int coin=0;
int pulse=0;
int total=0;
int RM=0;
//read coin value
void coin_value()
{
pulse=pulse+1;
}
void setup()
{
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(ten_sens,OUTPUT);
pinMode(twenty_sens,OUTPUT);
pinMode(fifty_sens,OUTPUT);
Serial.println("Ready to be collected");
}
void loop()
{
if (digitalRead(2) == HIGH)
{
attachInterrupt(0, coin_value, FALLING);
delay(300);
if(pulse==2)
{
Serial.println("500 kuning");
coin=500; //500
digitalWrite(fifty_sens,HIGH);
delay(1);
}
if(pulse==5)
{
Serial.println("500 silver");
coin=500; //500
digitalWrite(twenty_sens,HIGH);
delay(1);
}
if(pulse==10)
{
Serial.println("1000 chrome");
coin=1000; //1000
digitalWrite(ten_sens,HIGH);
delay(1);
}
}
digitalWrite(ten_sens,LOW);
digitalWrite(twenty_sens,LOW);
digitalWrite(fifty_sens,LOW);
coin=0;
pulse=0;
}