The Calamari lure makes use of may of the signals on the MinnowBoard Low Speed Expansion bus. In this example we will read from the Analog Digitcal Converter (ADC), visualize the data, and light an LED when the read value exceeds a threshold.
Import the modules and initialize the Calamari lure, then light the Red, Green, and Blue LEDs.
In [ ]:
from pyDrivers import calamari
c = calamari.calamari()
In [ ]:
c.led3.red(1)
c.led3.green(1)
c.led3.blue(1)
In [ ]:
print c.adc.read()
In [ ]:
import time
adc_values = []
x = range(0, 200)
for i in x:
adc_values.append(c.adc.read())
time.sleep(0.01)
print adc_values
Now that we have collected the data, we can plot it using matplotlib.
In [ ]:
%pylab inline
plot(x, adc_values)
Here we'll use the calamari's seven-segment display to write some basic characters. You can use any number from 0 to 9, and any character from A to F. You can put in individual characters, or a string. The second argument in the string function is how long to pause after displaying each character.
In [ ]:
c.sseg.putc("1")
time.sleep(1)
c.sseg.putc("2")
time.sleep(1)
c.sseg.putc("3")
time.sleep(1)
c.sseg.puts("ABC",1)
In [ ]:
for i in range(0,20):
current_value = c.adc.read()
if (0 <= current_value <= 400):
c.sseg.putc("A")
c.led3.blue(1)
c.led3.red(0)
c.led3.green(0)
elif (401<= current_value <=901):
c.sseg.putc("B")
c.led3.red(1)
c.led3.blue(0)
c.led3.green(0)
else:
c.sseg.putc("C")
c.led3.green(1)
c.led3.blue(0)
c.led3.green(0)
c.led3.red(0)
c.led3.blue(0)
c.led3.green(0)
In [ ]:
buttons = c.s1.wait()
print "Button 1 pressed!"
buttons = c.s2.wait()
print "Button 2 pressed!"
buttons = c.s3.wait()
print "Button 3 pressed!"
In [ ]: