Skillnad mellan versioner av "Grove - Slide Potentiometer"
(9 mellanliggande versioner av samma användare visas inte) | |||
Rad 1: | Rad 1: | ||
− | + | [[Fil:Grove-slide-pot.JPG|200px|thumb|right|Grove - Slide Potentiometer]] | |
− | |||
== Kompatibilitet == | == Kompatibilitet == | ||
* Arduino | * Arduino | ||
− | |||
== Port == | == Port == | ||
Rad 11: | Rad 9: | ||
== Exempelkod == | == Exempelkod == | ||
=== Arduino === | === Arduino === | ||
+ | |||
+ | Exempel implementeras med en [[Grove - LED]]-modul. | ||
+ | |||
<syntaxhighlight lang="C++" line> | <syntaxhighlight lang="C++" line> | ||
int adcPin = A0; // select the input pin for the potentiometer | int adcPin = A0; // select the input pin for the potentiometer | ||
Rad 32: | Rad 33: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | === Raspberry Pi === | ||
+ | |||
+ | <syntaxhighlight lang="Python" line> | ||
+ | import time | ||
+ | import grovepi | ||
+ | |||
+ | # Connect the Grove Slide Potentiometer to analog port A0 | ||
+ | slide = 0 # pin 1 (yellow wire) | ||
+ | # The device has an onboard LED accessible as pin 2 on port A0 | ||
+ | led = 1 # pin 2 (white wire) | ||
− | Mer information | + | grovepi.pinMode(slide,"INPUT") |
+ | grovepi.pinMode(led,"OUTPUT") | ||
+ | time.sleep(1) | ||
+ | |||
+ | while True: | ||
+ | try: | ||
+ | # Read sensor value from potentiometer | ||
+ | sensor_value = grovepi.analogRead(slide) | ||
+ | |||
+ | # Illuminate onboard LED | ||
+ | if sensor_value > 500: | ||
+ | grovepi.digitalWrite(led,1) | ||
+ | else: | ||
+ | grovepi.digitalWrite(led,0) | ||
+ | |||
+ | print "sensor_value =", sensor_value | ||
+ | |||
+ | except IOError: | ||
+ | print "Error" | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Mer information == | ||
+ | |||
+ | http://wiki.seeedstudio.com/Grove-Slide_Potentiometer/ | ||
[[Category:Grove]] | [[Category:Grove]] | ||
+ | [[Category:Grove-Sensor]] | ||
+ | |||
+ | [[Category:Kna-Wiki]] |
Nuvarande version från 4 februari 2021 kl. 07.30
Kompatibilitet
- Arduino
Port
- Analog
Exempelkod
Arduino
Exempel implementeras med en Grove - LED-modul.
int adcPin = A0; // select the input pin for the potentiometer
int ledPin = A1; // select the pin for the LED
int adcIn = 0; // variable to store the value coming from the sensor
void setup()
{
Serial.begin(9600); // init serial to 9600b/s
pinMode(ledPin, OUTPUT); // set ledPin to OUTPUT
Serial.println("Sliding Potentiometer Test Code!!");
}
void loop()
{
// read the value from the sensor:
adcIn = analogRead(adcPin);
if(adcIn >= 500) digitalWrite(ledPin,HIGH); // if adc in > 500, led light
else digitalWrite(ledPin, LOW);
Serial.println(adcIn);
delay(100);
}
Raspberry Pi
import time
import grovepi
# Connect the Grove Slide Potentiometer to analog port A0
slide = 0 # pin 1 (yellow wire)
# The device has an onboard LED accessible as pin 2 on port A0
led = 1 # pin 2 (white wire)
grovepi.pinMode(slide,"INPUT")
grovepi.pinMode(led,"OUTPUT")
time.sleep(1)
while True:
try:
# Read sensor value from potentiometer
sensor_value = grovepi.analogRead(slide)
# Illuminate onboard LED
if sensor_value > 500:
grovepi.digitalWrite(led,1)
else:
grovepi.digitalWrite(led,0)
print "sensor_value =", sensor_value
except IOError:
print "Error"