Skillnad mellan versioner av "Grove - Button"

Från Karlskrona Makerspace Wiki
Hoppa till: navigering, sök
 
Rad 61: Rad 61:
  
 
[[Category:Grove]]
 
[[Category:Grove]]
 +
[[Category:Grove-Sensor]]
 +
 
[[Category:Kna-Wiki]]
 
[[Category:Kna-Wiki]]

Nuvarande version från 4 februari 2021 kl. 07.25

Grove - Button

Momentanknapp (digital port: 0 eller 1) som studsar tillbaka efter intryckt.

Kompatibilitet

  • Arduino
  • Raspberry Pi

Port

  • Digital

Exempelkod

Arduino

const int pinButton = 3;                        // pin of button define here
const int pinLed    = 7;                        // pin of led define here

void setup()
{
    Serial.begin(9600);
    pinMode(pinButton, INPUT);                  // set button INPUT
    pinMode(pinLed, OUTPUT);                    // set led OUTPUT
}

void loop()
{
    if(digitalRead(pinButton))                     // when button is pressed
    {
        digitalWrite(pinLed, HIGH);             // led on
    }
    else
    {
        digitalWrite(pinLed, LOW);
    }
    Serial.println(digitalRead(pinButton));
    delay(10);
}

Raspberry Pi

import time
import grovepi

# Connect the Grove Button to digital port D3
# SIG,NC,VCC,GND
button = 3

grovepi.pinMode(button,"INPUT")

while True:
    try:
        print(grovepi.digitalRead(button))
        time.sleep(.5)

    except IOError:
        print ("Error")

Mer information

http://wiki.seeedstudio.com/Grove-Button/