port: |
Grove: A1 (C16, C17) |
interface: | analog |
output values |
1 - 1019 |
Further information: | https://wiki.seeedstudio.com/Grove-Rotary_Angle_Sensor/ |
A rotatable input knob (potentiometer) that can be turned up to 300° and produces a linear analog output between 0 and the operating voltage (3.3 V). This is distributed by the analog-digital converter of the Calliope mini in the value range between 0 and 1023.
Makecode
In MakeCode you can output the values of the Grove potentiometer via RX pin C16. To do this, go to the advanced blocks Pins and select the block analog values of pin P1 and change the pin accordingly to C16.
Since you usually want to permanently query the rotation of the potentiometer, the output should be in a permanent loop.
Map numbers
It may be useful to map the numbers from the range of values of the potentiometer into a new range of values, depending on the application. Under the category Mathematics you can find the block distribute 0 from low 0 from high....
Python
Die Werte des Rotary Angle Sensor können über den angeschlossenen Pin z.B. Grove-Pin pin_A1_RX über die Funktion read_analog() ausgelesen werden und in einer Variable gespeichert werden:
sensorwert = pin_A1_RX.read_analog()
Damit die Sensorwerte aktualisiert werde, müssen die analogen Werte innerhalb der While-Schleife ausgelesen werden.
from calliopemini import *
while True:
sensorwert = pin_A1_RX.read_analog() # Wert von 0–1023
if sensorwert < 300:
display.show(Image.SAD)
elif sensorwert < 600:
display.show(Image.MEH)
else:
display.show(Image.HAPPY)
sleep(1000)
You can find sensor and actuator projects that have already been realised on the project page.