Modifications

Sauter à la navigation Sauter à la recherche
1 982 octets ajoutés ,  9 décembre 2015 à 12:09
aucun résumé de modification
Ligne 18 : Ligne 18 :  
}}
 
}}
    +
== Utiliser l'écran LCD ==
 +
To get started using the LCD, try the following at the MicroPython prompt. Make sure the LCD skin is attached to the pyboard as pictured at the top of this page.
    +
<nowiki>>>> import pyb
 +
>>> lcd = pyb.LCD('X')
 +
>>> lcd.light(True)
 +
>>> lcd.write('Hello uPy!\n')</nowiki>
 +
 +
You can make a simple animation using the code:
 +
 +
<nowiki>import pyb
 +
lcd = pyb.LCD('X')
 +
lcd.light(True)
 +
for x in range(-80, 128):
 +
    lcd.fill(0)
 +
    lcd.text('Hello uPy!', x, 10, 1)
 +
    lcd.show()
 +
    pyb.delay(25)</nowiki>
 +
 +
== Utiliser le senseur tactile ==
 +
To read the touch-sensor data you need to use the I2C bus. The MPR121 capacitive touch sensor has address 90.
 +
 +
To get started, try:
 +
<nowiki>>>> import pyb
 +
>>> i2c = pyb.I2C(1, pyb.I2C.MASTER)
 +
>>> i2c.mem_write(4, 90, 0x5e)
 +
>>> touch = i2c.mem_read(1, 90, 0)[0]</nowiki>
 +
 +
The first line above makes an I2C object, and the second line enables the 4 touch sensors. The third line reads the touch status and the {{fname|touch}} variable holds the state of the 4 touch buttons (A, B, X, Y).
 +
 +
There is a simple driver [http://micropython.org/resources/examples/mpr121.py here] which allows you to set the threshold and debounce parameters, and easily read the touch status and electrode voltage levels. Copy this script to your pyboard (either flash or SD card, in the top directory or {{fname|lib/}} directory) and then try:
 +
 +
<nowiki>>>> import pyb
 +
>>> import mpr121
 +
>>> m = mpr121.MPR121(pyb.I2C(1, pyb.I2C.MASTER))
 +
>>> for i in range(100):
 +
...  print(m.touch_status())
 +
...  pyb.delay(100)
 +
...</nowiki>
 +
 +
This will continuously print out the touch status of all electrodes. Try touching each one in turn.
 +
 +
Note that if you put the LCD skin in the Y-position, then you need to initialise the I2C bus using:
 +
 +
<nowiki>>>> m = mpr121.MPR121(pyb.I2C(2, pyb.I2C.MASTER))</nowiki>
 +
 +
There is also a demo which uses the LCD and the touch sensors together, and can be found [http://micropython.org/resources/examples/lcddemo.py here].
    
{{MicroPython-LCD-TRAILER}}
 
{{MicroPython-LCD-TRAILER}}
29 917

modifications

Menu de navigation