Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- */
- const int LED_1 = 7;
- const int LED_2 = 9;
- const int BUTTON_IN = 6;
- const int STATO_SPENTO = 0;
- const int STATO_ACCESO = 1;
- const int STATO_LAMPEGGIA = 2;
- int stato = STATO_SPENTO;
- int lastButton = 0;
- int led2 = 1;
- // viene eseguita una sola volta
- void setup() {
- pinMode(LED_1, OUTPUT);
- pinMode(LED_2, OUTPUT);
- pinMode(BUTTON_IN, INPUT);
- }
- // viene eseguita in loop infinite volte
- void loop() {
- int button = digitalRead(BUTTON_IN);
- if(button == HIGH) {
- if(lastButton == 0) {
- if(led2 * 2 <= 255) led2 *= 2;
- else led2 = 1;
- analogWrite(LED_2, led2);
- lastButton = 1;
- switch(stato) {
- case STATO_SPENTO:
- stato = STATO_ACCESO;
- break;
- case STATO_ACCESO:
- stato = STATO_LAMPEGGIA;
- break;
- case STATO_LAMPEGGIA:
- stato = STATO_SPENTO;
- break;
- }
- delay(200);
- }
- } else {
- lastButton = 0;
- int luce1, luce2;
- if(stato == STATO_LAMPEGGIA) {
- luce1 = HIGH;
- luce2 = LOW;
- } else if(stato == STATO_SPENTO) {
- luce1 = LOW;
- luce2 = luce1;
- } else if(stato == STATO_ACCESO) {
- luce1 = HIGH;
- luce2 = luce1;
- } else {
- return;
- }
- digitalWrite(LED_1, luce1);
- delay(10);
- digitalWrite(LED_1, luce2);
- delay(100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment