Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions BreakfastSerial/components.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from BreakfastSerial import Arduino
from util import EventEmitter, setInterval, debounce
import pyfirmata, re, threading
from time import sleep

class ArduinoNotSuppliedException(Exception):
pass
Expand Down Expand Up @@ -167,6 +168,7 @@ def __init__(self, board, pin):
self._old_value = False
self._timeout = None

sleep(0.05)
self.change(self._emit_button_events)

def _handle_data(self):
Expand Down
Binary file added examples/01-blink-an-led/blink-circuit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/led.py → examples/01-blink-an-led/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
board = Arduino()
led = Led(board, 13)

led.blink(200)
led.blink(1000)

# Run an interactive shell so you can play (not required)
import code
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions examples/02-potentiometer/potentiometer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env python
"""
This is an example that demonstrates how to use a
potentiometer to change the blink speed of an LED
with BreakfastSerial. It assumes you have a
potentiometer wired up to pin A0 and a LED on pin 13.
"""
from BreakfastSerial import Arduino, Sensor, Led
from time import sleep

board = Arduino()
sensor = Sensor(board, "A0")
led = Led(board, 13)

while True:
led.on()
sleep(sensor.value)
led.off()
sleep(sensor.value)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions examples/05-push-buttons/push-buttons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env python
"""
This is an example that demonstrates how to use
buttons to toggle an LED with BreakfastSerial. It
assumes you have and LED wired up to pin 13 and
two buttons wired up to pins 2 and 3.
"""
from BreakfastSerial import Button, Led, Arduino

board = Arduino()

led = Led(board, 13)
button1 = Button(board, 2)
button2 = Button(board, 3)

for button in [button1, button2]:
button.up(led.toggle)
button.down(led.toggle)

# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()
26 changes: 26 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# About these examples

The examples in this folder are the python implementations of the examples
that Sparkfun distributes with it's [Inventor's Kit](https://www.sparkfun.com/products/11576).
The guidebook is distributed as PDF for free (link below). You can refer to
it for detailed circuit diagrams and information about the specific
components.

## [Click Here to Download the Guide](http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Kits/SFE03-0012-SIK.Guide-300dpi-01.pdf)

### Topics

1. Blinking an LED
2. Potentiometer (knob)
3. RGB (Red Green Blue) LED **(PENDING)**
4. Multiple LEDs **(PENDING)**
5. Push buttons
6. Photoresistor (light sensor) **(PENDING)**
7. Temperature sensor **(PENDING)**
8. Servomotor **(PENDING)**
9. Flex sensor **(PENDING)**
10. Soft potentiometer **(PENDING)**
11. Buzzer **(PENDING)**
12. Motor **(PENDING)**
13. Relay **(PENDING)**
14. Shift register **(PENDING)**
23 changes: 0 additions & 23 deletions examples/button.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ def change_led_brightness():
# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()

6 changes: 3 additions & 3 deletions examples/rgb_led.py → examples/misc/rgb_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"""
This is an example that demonstrates how to use an
RGB led with BreakfastSerial. It assumes you have an
RGB led wired up with red on pin 10, green on pin 9,
and blue on pin 8.
RGB led wired up with red on pin 9, green on pin 10,
and blue on pin 11.
"""
from BreakfastSerial import RGBLed, Arduino
from time import sleep

board = Arduino()
led = RGBLed(board, { "red": 10, "green": 9, "blue": 8 })
led = RGBLed(board, { "red": 9, "green": 10, "blue": 11 })

# Red (R: on, G: off, B: off)
led.red()
Expand Down
File renamed without changes.