Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
s-celles committed Feb 20, 2016
1 parent d8f20f7 commit 9590a16
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 42 deletions.
3 changes: 2 additions & 1 deletion pingo/examples/analog_bars.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pingo
from pingo import Mode
import time

board = pingo.detect.get_board()
# board = pingo.arduino.get_arduino()

pot = board.pins['A0']
pot.mode = pingo.ANALOG
pot.mode = Mode.ANALOG


def bar(pin):
Expand Down
3 changes: 2 additions & 1 deletion pingo/examples/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

import time
import pingo
from pingo import Mode

board = pingo.detect.get_board()
led = board.pins[13]
led.mode = pingo.OUT
led.mode = Mode.OUT

while True:
led.toggle()
Expand Down
3 changes: 2 additions & 1 deletion pingo/examples/blink_firmata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

import time
import pingo
from pingo import Mode

ard = pingo.arduino.ArduinoFirmata('/dev/tty.usbmodemfa1341')
print('Connected to: %s' % ard)
led = ard.pins[13]
led.mode = pingo.OUT
led.mode = Mode.OUT

while True:
led.toggle()
Expand Down
3 changes: 2 additions & 1 deletion pingo/examples/blink_firmata_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

import time
import pingo
from pingo import Mode

ard = pingo.arduino.get_arduino()
print('Connected to: %s' % ard)
led = ard.pins[13]
led.mode = pingo.OUT
led.mode = Mode.OUT

while True:
led.toggle()
Expand Down
7 changes: 4 additions & 3 deletions pingo/examples/dimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@

from pprint import pprint
import pingo
from pingo import Mode
import time

board = pingo.detect.get_board()

pot = board.pins['A0']
pot.mode = pingo.ANALOG
pot.mode = Mode.ANALOG

led = board.pins[6]
led.mode = pingo.PWM
led.mode = Mode.PWM

display_pins = [board.pins[i] for i in range(8, 14) + [7]]
seg_display = pingo.parts.led.SevenSegments(*display_pins)
for pin in display_pins:
pin.mode = pingo.OUT
pin.mode = Mode.OUT


def bar(pin):
Expand Down
7 changes: 4 additions & 3 deletions pingo/examples/dojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@

import time
import pingo
from pingo import Mode

board = pingo.detect.get_board()
print('board: %s' % board)
pot = board.pins['A0']
pot.mode = pingo.ANALOG
pot.mode = Mode.ANALOG
leds = board.digital_pins[6:14]

for led in leds:
led.mode = pingo.OUT
led.mode = Mode.OUT
led.low()

while True:
Expand All @@ -30,5 +31,5 @@
continue
led.high()
time.sleep(pot.ratio())
print pot.ratio()
print(pot.ratio())
led.low()
3 changes: 2 additions & 1 deletion pingo/examples/dojo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from time import sleep
import pingo
from pingo import Mode

POT_LOCATION = 'A0'
PIN_LOCATIONS = range(6, 14)
Expand All @@ -21,7 +22,7 @@
leds = (pingo.pins[loc] for loc in PIN_LOCATIONS if loc != 9)

for led in leds:
led.mode = pingo.OUT
led.mode = Mode.OUT

while True:
for led in leds:
Expand Down
9 changes: 5 additions & 4 deletions pingo/examples/dojoxxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"""

import pingo
from pingo import Mode
import time

ard = pingo.arduino.get_arduino()
print '*' * 60
print('*' * 60)

segments = [
11, # A
Expand All @@ -20,17 +21,17 @@

for seg in segments:
pin = ard.pins[seg]
pin.mode = pingo.OUT
pin.mode = Mode.OUT
pin.low()

pot = ard.pins['A0']
pot.mode = pingo.IN
pot.mode = Mode.IN

while True:
for seg in segments:
pin = ard.pins[seg]
pin.high()
delay = pot.ratio() + 0.01 # add 0.01s delay for communication
print '%0.3f' % delay
print('%0.3f' % delay)
time.sleep(delay)
pin.low()
5 changes: 3 additions & 2 deletions pingo/examples/double_blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

import time
import pingo
from pingo import Mode

board = pingo.rpi.RaspberryPiBPlus()
local_led = board.pins[13]
local_led.mode = pingo.OUT
local_led.mode = Mode.OUT

ard = pingo.arduino.get_arduino()
remote_led = ard.pins[13]
remote_led.mode = pingo.OUT
remote_led.mode = Mode.OUT

local_led.low() # for an common anode RGB LED
remote_led.low()
Expand Down
7 changes: 4 additions & 3 deletions pingo/examples/dual_analog_bars.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import pingo
import time
from pingo import Mode

galileo = pingo.detect.get_board()
arduino = pingo.arduino.get_arduino()

pot_galileo = galileo.pins['A0']
pot_galileo.mode = pingo.ANALOG
pot_galileo.mode = Mode.ANALOG

pot_arduino = arduino.pins['A0']
pot_arduino.mode = pingo.ANALOG
pot_arduino.mode = Mode.ANALOG


def bar(pin1, pin2):
bar1 = ('*' * int(pin1.ratio() * 40)).ljust(40)
bar2 = ('*' * int(pin2.ratio() * 40)).rjust(40)
print bar2 + bar1
print(bar2 + bar1)

while True:
bar(pot_galileo, pot_arduino)
Expand Down
7 changes: 4 additions & 3 deletions pingo/examples/galileo_analog_bars.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import pingo
import time
import pingo
from pingo import Mode

board = pingo.galileo.Galileo2()

pot = board.pins['A0']
pot.mode = pingo.ANALOG
pot.mode = Mode.ANALOG


def bar(pin):
print "*" * int(pin.ratio() * 70)
print("*" * int(pin.ratio() * 70))

while True:
bar(pot)
Expand Down
7 changes: 4 additions & 3 deletions pingo/examples/map7segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
"""

import pingo
from pingo import Mode

ard = pingo.arduino.get_arduino()
print '*' * 60
print('*' * 60)
segs = {}

for i in range(14):
pin = ard.pins[i]
pin.mode = pingo.OUT
pin.mode = Mode.OUT
pin.hi()
seg = raw_input('Pin %s -> segment: ' % i).strip()
if seg:
segs[seg] = i
pin.low()

for seg, pin in sorted(segs.items()):
print '%s, # %s' % (pin, seg)
print('%s, # %s' % (pin, seg))
4 changes: 2 additions & 2 deletions pingo/examples/parts/7seg_demo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Seven segment display demo using the Garoa Dojo Shield """

from time import sleep
from pingo import OUT, detect, parts
from pingo import Mode, detect, parts

INTERVAL = 0.3

Expand All @@ -10,7 +10,7 @@
display_pins = [ard.pins[i] for i in range(8, 14) + [7]]

for pin in display_pins:
pin.mode = OUT
pin.mode = Mode.OUT

seg_display = parts.led.SevenSegments(*display_pins)

Expand Down
2 changes: 1 addition & 1 deletion pingo/examples/parts/led_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
a_state = '*A*' if a_led.lit else ' a '
b_state = '*B*' if b_led.lit else ' b '

print time.strftime('%H:%M:%S'), a_state, b_state
print("%s %s %s" % (time.strftime('%H:%M:%S'), a_state, b_state))
time.sleep(.1)
5 changes: 3 additions & 2 deletions pingo/examples/pongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import curses
import pingo
from pingo import Mode
import time
import random

Expand Down Expand Up @@ -64,10 +65,10 @@ def draw_paddle(x, y, color):
arduino = pingo.arduino.get_arduino()

pot_galileo = galileo.pins['A0']
pot_galileo.mode = pingo.ANALOG
pot_galileo.mode = Mode.ANALOG

pot_arduino = arduino.pins['A0']
pot_arduino.mode = pingo.ANALOG
pot_arduino.mode = Mode.ANALOG

# Read the initial values of the paddles
paddle_1_pos = int(pot_arduino.ratio(to_min=MIN_Y, to_max=MAX_Y-PADDLE_SIZE))
Expand Down
3 changes: 2 additions & 1 deletion pingo/examples/probe_pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys

import pingo
from pingo import Mode


def probe(first, last):
Expand All @@ -16,7 +17,7 @@ def probe(first, last):
pins = board.digital_pins[first:last + 1]

for pin in pins:
pin.mode = pingo.OUT
pin.mode = Mode.OUT

for pin in pins:
pin.hi()
Expand Down
7 changes: 4 additions & 3 deletions pingo/examples/pwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

from pprint import pprint
import pingo
from pingo import Mode
import time

board = pingo.detect.get_board()
print board

board = pingo.detect.get_board()
print(board)

led = board.pins[6]
led.mode = pingo.PWM
led.mode = Mode.PWM

pprint(board.pins, indent=4, width=1)

Expand Down
3 changes: 2 additions & 1 deletion pingo/examples/rgb_led.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import time

import pingo
from pingo import Mode

board = pingo.detect.get_board()

rgb = [board.pins[i] for i in (11, 13, 15)]

for pin in rgb:
pin.mode = pingo.OUT
pin.mode = Mode.OUT
pin.low()

while True:
Expand Down
3 changes: 2 additions & 1 deletion pingo/examples/rpi_examples/display7.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pingo
from pingo import Mode
import time

rpi = pingo.rpi.RaspberryPi()
Expand All @@ -9,7 +10,7 @@
if pin.location in led_locations]

for pin in pins:
pin.mode = pingo.OUT
pin.mode = Mode.OUT

for pin in pins:
pin.high()
Expand Down
3 changes: 2 additions & 1 deletion pingo/examples/rpi_examples/display7_anim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pingo
from pingo import Mode
from time import sleep

rpi = pingo.rpi.RaspberryPi()
Expand All @@ -9,7 +10,7 @@
pins = [rpi.pins[loc] for loc in led_locations[:6]]

for pin in pins:
pin.mode = pingo.OUT
pin.mode = Mode.OUT
pin.low()

while True:
Expand Down
3 changes: 2 additions & 1 deletion pingo/examples/rpi_examples/display7_probe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pingo
from pingo import Mode

rpi = pingo.rpi.RaspberryPi()

Expand All @@ -7,7 +8,7 @@
pins = [rpi.pins[loc] for loc in led_locations]

for pin in pins:
pin.mode = pingo.OUT
pin.mode = Mode.OUT
pin.low()

for pin in pins:
Expand Down
Loading

0 comments on commit 9590a16

Please sign in to comment.