def eggtimer(i2c): pot = EDS.Pot(i2c) beep = EDS.Beep(i2c) digits = EDS.Dig2(i2c) ticking = False v0 = pot.rd(99) next = millis() + 4000 digits.brightness(50) t = 0 while True: v = pot.rd(99) if v0 != v: if v0 < v: beep.beep(2, 80) else: beep.beep(1, 117) ticking = False next = millis() + 1000 v0 = v digits.brightness(255) t = v digits.dec(t) if millis() > next and (t != 0): ticking = True if ticking and millis() > next: next = millis() + 1000 beep.beep(1, 120) if t: t -= 1 else: for i in range(21): digits.brightness(255) beep.beep(75, 107) time.sleep(.1) digits.brightness(0) time.sleep(.05) digits.brightness(50) ticking = False
import sys import serial import time from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) d = EDS.Dig2(i2) for i in range(100): d.dec(i) time.sleep(.05)
import sys import serial import time import struct import random from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) d = EDS.LED(i2) TEAL = 0x008080 ORANGE = 0xffa500 while 1: time.sleep(1) d.hex(TEAL, 3) time.sleep(1) d.hex(ORANGE, 3)
import sys import struct import time from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) d = EDS.Magnet(i2) while 1: print(d.measurement())
import sys import time from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1], True) i2.setspeed(400) d = EDS.Remote(i2) print("Press a remote button") while 1: k = d.key() if k is not None: print("Key : %r" % k) r = d.raw() if r is not None: (code, timestamp) = r print("Raw code: %02x %02x %02x %02x (time %.2f)" % (code[0], code[1], code[2], code[3], timestamp)) time.sleep(.25)
ships from China; some high aloft in the rigging, as if striving to get a still better seaward peep. But these are all landsmen; of week days pent up in lath and plaster-tied to counters, nailed to benches, clinched to desks. How then is this? Are the green fields gone? What do they here? But look! here come more crowds, pacing straight for the water, and seemingly bound for a dive. Strange! Nothing will content them but the extremest limit of the land; loitering under the shady lee of yonder warehouses will not suffice. No. They must get just as nigh the water as they possibly can without falling in. And there they stand-miles of them-leagues. Inlanders all, they come from lanes and alleys, streets and avenues-north, east, south, and west. Yet here they all unite. Tell me, does the magnetic virtue of the needles of the compasses of all those ships attract them thither? Once more. Say you are in the country; in some high land of lakes. Take almost any path you please, and ten to one it carries you down in a dale, and leaves you there by a pool in the stream. There is magic in it. Let the most absent-minded of men be plunged in his deepest reveries-stand that man on his legs, set his feet a-going, and he will infallibly lead you to water, if water there be in all that region. Should you ever be athirst in the great American desert, try this experiment, if your caravan happen to be supplied with a metaphysical professor. Yes, as every one knows, meditation and water are wedded for ever. """ if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) d = EDS.EPROM(i2) d.write(0, text) # Write the block of text starting at address 0 n = len(text) rd = d.read(0, n) # Read it back print(rd.decode()) # Display it
import sys import time from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) d = EDS.Clock(i2) d.set() while 1: print(d.read()) time.sleep(1)
class Mux: def __init__(self, i2, a=0x70): self.i2 = i2 self.a = a def select(self, n): assert n in range(8) self.i2.start(self.a, 0) self.i2.write([1 << n]) self.i2.stop() if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) mux = Mux(i2) sensors = [(0, EDS.Temp(i2)), (1, EDS.Temp(i2)), (2, EDS.Temp(i2))] # Reset all 8 channels for chan in range(8): mux.select(chan) i2.reset() def read(chan, dev): mux.select(chan) celsius = dev.read() return celsius while 1: print(" ".join(["%.1f" % read(chan, dev) for chan, dev in sensors]))
""" Demo of a simple combination of parts from Electric Dollar Store: * MAGNET - 3-axis magnetometer * LED - RGB LED This demo takes the compass direction, and uses it to set the LED's color. So as you move the module around, the color changes according to its direction. There is a direction that is pure red, another that is pure green, etc. https://electricdollarstore.com """ import sys from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) magnet = EDS.Magnet(i2) led = EDS.LED(i2) while True: (x, y, z) = magnet.measurement() r = max(0, min(255, (x + 4000) // 32)) g = max(0, min(255, (y + 4000) // 32)) b = max(0, min(255, (z + 4000) // 32)) led.rgb(r, g, b)
It shows 2-digit "now serving" number, and each time '+' is pressed on the remote it increments the counter and makes a beep, so the next customer can be served. Pressing '-' turns the number back one. https://electricdollarstore.com """ import sys from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) remote = EDS.Remote(i2) beep = EDS.Beep(i2) dig2 = EDS.Dig2(i2) counter = 0 while True: k = remote.key() if k == '+': beep.beep(255, 90) counter = (counter + 1) % 100 if k == '-': beep.beep(100, 80) counter = (counter - 1) % 100 dig2.dec(counter)
import sys import struct import time from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) d = EDS.Pot(i2) while 1: percentage = d.rd(100) r = d.raw() print("%3d/100 raw=%3d" % (percentage, r)) time.sleep(.05)
import sys import serial import time import struct import random from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1], True) d = EDS.Beep(i2) for note in range(55, 127): print("MIDI note %d" % note) d.beep(100, note) time.sleep(.100)
import sys import time from i2cdriver import I2CDriver, EDS if __name__ == '__main__': i2 = I2CDriver(sys.argv[1]) d = EDS.Temp(i2) for i in range(20): celsius = d.read() fahrenheit = celsius * 9 / 5 + 32 sys.stdout.write("%.1f C %.1f F\n" % (celsius, fahrenheit)) time.sleep(.1)