Skip to content

Instantly share code, notes, and snippets.

@lfzawacki
Last active August 29, 2015 14:18
Show Gist options
  • Save lfzawacki/d1b78609584253a25f3a to your computer and use it in GitHub Desktop.
Save lfzawacki/d1b78609584253a25f3a to your computer and use it in GitHub Desktop.
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