LED bicolor Red Green

Hi,

it's saturday evening... you're probably around drinking beer or to make love but i must do a study case for a stupid exam for my university... nice... it's time to my Raspberry Pi and my dream of ruling the world.

This time what i want to do is to switch a bicolor LED from red to green

This is a bicolor LED:


A bicolor LED has three pins.. Two anode for red color and green color and a cathode. Remember that cathode is the longest, green is the second longest pin and red is the shortest pin.

What i need:

  • one bicolor LED
  • three resistor of 330 ohm
  • one beer
  • something that entice me to study

this connection is pretty simple:
put bicolor LED on breadboard. Connect ground on RaspberryPi to blue track  ob breadboard. Use one 330 ohm resistor to connect the cathode pin to blue track on breadboard. Connect pin 18 on Raspberry to green LED pin (and place a 330 ohm resistor in the middle) then connect pin 24 on Raspberry to red LED pin (and place a resistor in the middle). Ok it's done.
This is the schema

 
from schema to real:


ok it's sprengsteen time https://www.youtube.com/watch?v=O_BuT8qg4lA

Ok this is the code:

# LED RG (Red Green)

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.OUT)
GPIO.output(18, 1)

GPIO.setup(24, GPIO.OUT)
GPIO.output(24, 1)

try:
    while True:
        request = raw_input("Insert an Red Green combination: ")
        if(len(request) == 2):
            GPIO.output(18, int(request[0]))
            GPIO.output(24, int(request[1]))

except KeyboardInterrupt:
    GPIO.cleanup()


(this code is inspired by this video https://www.youtube.com/watch?v=b4_R1eX9K6s

and this is the result:





good night

Commenti