quarta-feira, 7 de junho de 2017

PROGRAMA BOTÃO FASE 1

Copiem este programa na tela do arduino:

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
int cont = 0;
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    cont = cont + 1;
    Serial.println(cont);
    delay(100);
    if (cont == 5)
    {
      cont = 0;
    }
   
    }
    if(cont == 1)
    {
      digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
delay(1000);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
delay(1000);
    }
     if(cont == 2)
    {
   
digitalWrite(4,HIGH);

delay(1000);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
delay(1000);
    }
    else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Nenhum comentário:

Postar um comentário