Grove - Button

Från Karlskrona Makerspace Wiki
Hoppa till: navigering, sök
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/