Paso 14: Añadir este código en su placa
//Parts of this is commented out for the infrared diffuser that will be placed in the instructions later #include <AccelStepper.h> //#define IRPIN A0 // Pin for the input from infrared diffuser int ofs = 5; // pin for out of stock sensor int led = 13; // out of stock led const int coinInt = 0; // interrupt pin number (insert the wire into pin 2 in arduino) int pencilDispensed = 11; volatile float coinVal = 0.00; // set to volatile for the interrupt function(so it is properly updated) int coinIn = 0; AccelStepper stepper(1,9,8); void setup() { Serial.begin(9600); stepper.setMaxSpeed(3000); stepper.setSpeed(3000); attachInterrupt(coinInt, coin, RISING); pinMode(ofs, INPUT); pinMode(led, OUTPUT); //pinMode(IRPIN, INPUT); } void coin() { coinVal = coinVal + 0.05; coinIn = 1; }void pencil(){ Serial.println("Pencil"); } void loop() { int outofstock = digitalRead(ofs); if(outofstock == 1){ digitalWrite(led,HIGH); } else{ digitalWrite(led,LOW); } if(coinIn == 1) //Check if coin has been inserted { if(outofstock == 1){ coinIn = 0; } else{ coinVal = 0; //while(!digitalRead(pencilDispensed)){ stepper.runSpeed(); //} coinIn = 0; } } }