Skip to content

Instantly share code, notes, and snippets.

@arielchuri
Last active September 23, 2015 22:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arielchuri/9f796871d14b543a47ef to your computer and use it in GitHub Desktop.
Save arielchuri/9f796871d14b543a47ef to your computer and use it in GitHub Desktop.
Sample code for Core Object Week 3-1
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