Skip to content

Instantly share code, notes, and snippets.

@lfzawacki
Last active Aug 29, 2015
Embed
What would you like to do?
Introdução a Programação com Arduino (28/03/15)
/*
Por Lucas Zawacki e galera da oficina de introdução a Arduino
https://matehackers.org/arduino_day_2015
*/
const int buttonPin = 2;
const int buzzerPin = 11;
const int sensorPin = 4;
const int ledPin = 13;
int buttonState = 0;
int sensorState = 0;
boolean on = false;
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(sensorPin, INPUT);
}
void loop(){
buttonState = digitalRead(buttonPin);
sensorState = digitalRead(sensorPin);
if (buttonState == HIGH) {
on = !on;
delay(1000);
}
if(!on) {
digitalWrite(ledPin, LOW);
}
else
{
digitalWrite(ledPin, HIGH);
}
if (on && sensorState == HIGH) {
digitalWrite(buzzerPin, HIGH);
}
else {
digitalWrite(buzzerPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment