Skip to content

Commit

Permalink
use object based interface in more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ponty committed Feb 27, 2014
1 parent 647504a commit 36ab8c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions nanpy/__init__.py
Expand Up @@ -23,3 +23,5 @@
from nanpy.tone import Tone
from nanpy.capacitivesensor import CapacitiveSensor
from nanpy.dht import DHT
from nanpy.arduinoapi import ArduinoApi
from nanpy.eepromobj import EepromLib
12 changes: 8 additions & 4 deletions nanpy/examples/blink.py
Expand Up @@ -4,11 +4,15 @@
# Description: keeps your led blinking
# Dependencies: None

from nanpy import Arduino
from nanpy import (ArduinoApi, SerialManager)
from time import sleep

Arduino.pinMode(13, Arduino.OUTPUT)
connection = SerialManager()
a = ArduinoApi(connection=connection)

a.pinMode(13, a.OUTPUT)

for i in range(10000):
Arduino.digitalWrite(13, (i + 1) % 2)
Arduino.delay(200)
a.digitalWrite(13, (i + 1) % 2)
sleep(0.2)

9 changes: 6 additions & 3 deletions nanpy/examples/clock.py
Expand Up @@ -5,8 +5,11 @@
# Dependencies: ntplib (http://pypi.python.org/pypi/ntplib/)

import ntplib
from nanpy import (Arduino, Lcd)
from nanpy import (SerialManager, Lcd)
from datetime import datetime
from time import sleep

connection = SerialManager()

ntp_client = ntplib.NTPClient()
response = ntp_client.request('europe.pool.ntp.org', version=3)
Expand All @@ -15,7 +18,7 @@

pins = [7, 8, 9, 10, 11, 12]
cols, rows = 16, 2
lcd = Lcd(pins, [cols, rows])
lcd = Lcd(pins, [cols, rows], connection=connection)

while (1):
lcd.setCursor(0, 0)
Expand All @@ -26,5 +29,5 @@
time_format = '%H %M'
lcd.setCursor(0, 1)
lcd.printString((datetime.fromtimestamp(time)).strftime(time_format))
Arduino.delay(1000)
sleep(1)
time += 1
15 changes: 8 additions & 7 deletions nanpy/examples/eepromread.py
@@ -1,30 +1,31 @@
#!/usr/bin/env python

# Author: Kevin Ng
# Author: Kevin Ng
# Description: read from EEPROM
# Dependencies: None

from nanpy import EEPROM
from nanpy import (EepromLib, SerialManager)
import sys

EEPROM_SIZE = EEPROM.size()
connection = SerialManager()
e = EepromLib(connection=connection)


def display(a_list):
for i in range(0, EEPROM_SIZE//16-1):
for i in range(0, e.size // 16 - 1):
for j in range(16):
sys.stdout.write("%02x:" % a_list[j + i * 16])
print


def read_eeprom():
data_list = []
for i in range(0, EEPROM_SIZE):
s = EEPROM.read(i)
for i in range(0, e.size):
s = e.read(i)
data_list.append(s)
return data_list


if __name__ == "__main__":
print("Reading eeprom (%s bytes)..." % EEPROM_SIZE)
print("Reading eeprom (%s bytes)..." % e.size)
display(read_eeprom())

0 comments on commit 36ab8c8

Please sign in to comment.