Last active
September 23, 2015 22:51
-
-
Save arielchuri/9f796871d14b543a47ef to your computer and use it in GitHub Desktop.
Sample code for Core Object Week 3-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Moved to the class repo at https://github.com/coreobject/class | |
const int buttonPin = 2; | |
const int ledPin = 12; | |
const int fadeLed = 11; | |
int ledState = LOW; | |
int buttonState = 0; | |
int fadeLevel = 0; | |
boolean pressed = false; | |
void setup() { | |
pinMode(ledPin, OUTPUT); | |
pinMode(buttonPin, INPUT); | |
pinMode(fadeLed, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
// read the state of the pushbutton value: | |
buttonState = digitalRead(buttonPin); | |
if (buttonState == HIGH && pressed == false ) { | |
// turn LED on: | |
if (ledState == LOW) { | |
ledState = HIGH; | |
Serial.println("bang"); | |
} | |
else { | |
ledState = LOW; | |
} | |
pressed = true; | |
} | |
if (buttonState == LOW && pressed == true ) { | |
pressed = false; | |
} | |
fadeLevel++; | |
digitalWrite(ledPin, ledState); | |
analogWrite(fadeLed,fadeLevel); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment