Skip to content

Commit

Permalink
Add initial exp2: pushbutton LED
Browse files Browse the repository at this point in the history
  • Loading branch information
jharwell committed Oct 15, 2018
1 parent c68b727 commit 42482e8
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,16 @@
* For more information, please refer to <http://unlicense.org/>
*/

/*
* The pin # of the LED we are going to use.
*/
/* The pin # of the LED. */
#define LED_PIN 13

/*
* 1-time setup code that runs during initialization.
*/
/* 1-time setup code that runs during initialization. */
void setup(void) {
pinMode(LED_PIN, OUTPUT);
}

/*
* Main code, which will run forever.
*/
void loopvoid() {
/* Main code, which will run forever. */
void loop(void) {
digitalWrite(LED_PIN, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* General notes
- How much of the code should be given to them? Maybe give them a choice between building off of the previous experiment
to try to make the LED controlled by a push button, and just giving them the code?

* Extensions
- Can you change the PIN in the code and figure out how to still get the LED to blink?
- Can you make 2 LEDs blink at the same time from a single pin?
Expand Down
9 changes: 9 additions & 0 deletions exp2-pushbutton-led/exp2-notes.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* General notes
- Some pushbuttons are a little sticky; if you don't firmly press down on them, they can get stuck on and make you think
your circuit or your code is wrong.
- This exp is basically 2 circuits. Build each in turn, starting with the LED circuit from exp1.

* Extensions
- Can you make the LED turn on when the button is not pressed?
- Can you make it take 2 button presses to turn on the LED?
- Can you make 1 LED turn on when the button is being pressed, and another when it is not pressed?
53 changes: 53 additions & 0 deletions exp2-pushbutton-led/pushbutton-led.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @file pushbutton-led.ino
*
* This is free and unencumbered software released into the public domain.
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org/>
*/

/* The pin # of the pushbutton */
const int BTN_PIN = 2;

/* The pin # of the LED */
const int LED_PIN1 = 12;
const int LED_PIN2 = 8;

/* 1-time setup code that runs during initialization. */
void setup(void) {
pinMode(LED_PIN1, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
pinMode(BTN_PIN, INPUT);
}

/* Main code, which will run forever. */
void loop(void) {
int btn_state = digitalRead(BTN_PIN);
if (HIGH == btn_state) {
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN2, LOW);
} else {
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, HIGH);
}
}
12 changes: 12 additions & 0 deletions notes.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* Introduction
- Should probably walk everyone through the very first blinking LED project, so they see how to use the IDE, program the
board, and do a bit of programming. If things go well, this might also be a good idea to do periodically, so if new
people come to the classes, they can get a nice intro without feeling lost.

* Construction
- How much of circuit diagram stuff should I go into? Will it help? Basic stuff like voltage, current, resistance, are
necessary at least.

* Safety
- Don't worry about shorting/breaking stuff. Try not to, but some of that is part of the learning experience.
- If you aren't sure if something will short out, ask!

0 comments on commit 42482e8

Please sign in to comment.