Skillnad mellan versioner av "Grove - LED"

Från Karlskrona Makerspace Wiki
Hoppa till: navigering, sök
 
 
(En mellanliggande version av samma användare visas inte)
Rad 75: Rad 75:
  
 
[[Category:Grove]]
 
[[Category:Grove]]
 +
[[Category: Grove-Display]]
 +
[[Category:Kna-Wiki]]

Nuvarande version från 4 februari 2021 kl. 07.43

Grove - LED

Grove - LED-modul som rymmer en LED-ljuskälla. Dessutom har den även en potentiometer ombord för att hantera LED-kraven.

Kompatibilitet

  • Arduino
  • Raspberry Pi

Port

  • Digital

(möjligt att kontrollera med PWM för att åstadkomma fading).

Exempelkod

Arduino

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

void setup()
{
    pinMode(pinLed, OUTPUT);                    // set led OUTPUT
}

void loop()
{
    for(int i=0; i<256; i++)
    {
        analogWrite(pinLed, i);
        delay(5);                               // change delay time can breath faster or slower
    }
    delay(100);
    for(int i=254; i>=0; i--)
    {
        analogWrite(pinLed, i);
        delay(5);                               // change delay time can breath faster or slower
    }
    delay(500);
}

Raspberry Pi

import time
from grovepi import *

# Connect the Grove LED to digital port D4
led = 4

pinMode(led,"OUTPUT")
time.sleep(1)

print ("This example will blink a Grove LED connected to the GrovePi+ on the port labeled D4. If you're having trouble seeing the LED blink, be sure to check the LED connection and the port number. You may also try reversing the direction of the LED on the sensor.")
print (" ")
print ("Connect the LED to the port labele D4!" )

while True:
    try:
        #Blink the LED
        digitalWrite(led,1)     # Send HIGH to switch on LED
        print ("LED ON!")
        time.sleep(1)

        digitalWrite(led,0)     # Send LOW to switch off LED
        print ("LED OFF!")
        time.sleep(1)

    except KeyboardInterrupt:   # Turn LED off before stopping
        digitalWrite(led,0)
        break
    except IOError:             # Print "Error" if communication error encountered
        print ("Error")

Mer information

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