from gpiozero import MCP3208, RGBLED from time import sleep led = RGBLED(red=19,green=21,blue=26) adc = MCP3208(channel=1) led.color = (0,178/255,1) while True: voltage = 3.3*adc.value print(voltage) sleep(0.5)
# Declaramos el led led = RGBLED(12, 16, 20) # Definimos el modo BCH GPIO.setmode(GPIO.BCM) # Ahora definimos el pin GPIO 18 como salida GPIO.setup(18, GPIO.OUT) # Realizamos el ciclo while True: tecla = key.getch() # obtenemos la tecla presionada if tecla == 27: # Teclas direccionales, que va a encender el LED Rojo led.on() led.off() led.color = (1, 0, 0) # Rojo if tecla == 32: # Tecla de espacio, que va a encender el LED Verde led.on() led.off() led.color = (0, 1, 0) # Verde if tecla == 119: # Tecla W , que va a encender el LED Azul led.on() led.off() led.color = (0, 0, 1) # Azul if tecla == 103: # Tecla G, para apagar LEDS GPIO.cleanup() # Limpiamos los Pines
from gpiozero import RGBLED from colorzero import Color from time import sleep led = RGBLED(red=16, green=20, blue=21) led.color = Color('#f80c12') sleep(1) led.color = Color('#ee1100') sleep(1) led.color = Color('#ff3311') sleep(1) led.color = Color('#ff4422') sleep(1) led.color = Color('#ff6644') sleep(1) led.color = Color('#ff9933') sleep(1) led.color = Color('#feae2d') sleep(1) led.color = Color('#ccbb33') sleep(1) led.color = Color('#d0c310') sleep(1) led.color = Color('#aacc22') sleep(1) led.color = Color('#69d025') sleep(1) led.color = Color('#22ccaa') sleep(1)
from gpiozero import RGBLED from colorzero import Color from time import sleep #define pins led = RGBLED(green=10,red=9,blue=11,active_high=False) # common anode RBG LED! led.on() sleep(1) led.off() led.color = Color("yellow") sleep(1) led.color = Color("purple") sleep(1) led.toggle() #invert sleep(1) led.blink(on_time=1.5, off_time=0.5, fade_in_time=0.5, fade_out_time=0.5, on_color=(1, 0.3, 1), off_color=(0, 1, 0), n=10, background=False) led.off() print("done") led.close()
from gpiozero import RGBLED from time import sleep led = RGBLED(red=21, green=20, blue=19) led.color = (0, 1, 1) sleep(3) led.color = (1, 1, 1)
import socket import json from gpiozero import RGBLED # UDP receiver client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) client.bind(("", 37020)) # RGB led led = RGBLED(14, 15, 18, active_high=True, pwm=True) while True: data, addr = client.recvfrom(1024) data = json.loads(data.decode('utf-8')) # set object property # tuple # dictionary led.color = (data['red'] / 255, data['green'] / 255, data['blue'] / 255) print(data)
# Common cathode RGB led. from gpiozero import RGBLED from time import sleep import sys import os led = RGBLED(2, 3, 4, active_high=True) delay = 1 led.red = 1 # full red sleep(delay) led.red = 0.5 # half red sleep(delay) led.color = (0, 1, 0) # full green sleep(delay) led.color = (0, 0.5, 0) # half green sleep(delay) led.color = (0, 0, 1) # full blue sleep(delay) led.color = (0, 0, 0.5) # half blue sleep(delay) led.color = (1, 0, 1) # magenta sleep(delay) led.color = (1, 1, 0) # yellow sleep(delay) led.color = (0, 1, 1) # cyan sleep(delay) led.color = (1, 1, 1) # white
from gpiozero import Button, RGBLED button = Button(18) rgbLed = RGBLED(17, 27, 22) rgbLed.color = (1, 0, 0) while True: if button.is_pressed: print("Button is pressed") rgbLed.color = (0, 0, 0) else: print("Button is not pressed") rgbLed.color = (0, 1, 0)
btnRed = Button(19) btnBlue = Button(26) #btnRed.is_pressed RGB = RGBLED(22, 27, 17) i = .01 j = 0.1 try: while (1): '''if btnRed.is_pressed and i!=0 : i = 0 RGB.color = (1,0,0) time.sleep(j)''' '''time.sleep(i) RGB.color = (0,1,0) time.sleep(i) RGB.color = (0,0,1) time.sleep(i)''' '''elif btnRed.is_pressed and i==0: RGB.off() i = 1 time.sleep(j)''' RGB.color = (1, 0, 0) #time.sleep(j) time.sleep(i) RGB.color = (0, 1, 0) time.sleep(i) RGB.color = (0, 0, 1) time.sleep(i) except KeyboardInterrupt: RGB.off()
from gpiozero import RGBLED from time import sleep from colorzero import Color led = RGBLED(18, 23, 24) led.color = Color('red') sleep(2) led.color = Color('green') sleep(2) led.color = Color('blue') sleep(2) led.color = Color('white') sleep(2)
import scrollphat except (ImportError, IOError) as e: logging.warn(e, exc_info=True) logging.warn( "Failed to load Scroll pHAT library, you'll be missing all the fancy graphics" ) scrollphat = None rgb_led = RGBLED(20, 21, 26) _running = False _output = () _first_time = True rgb_led.color = (1, 0, 0) def render(): # LED check scrollphat.clear_buffer() for col in range(0, 13): if col > 1: scrollphat.set_col(col - 2, 0) if col < 11: scrollphat.set_col(col, 0b11111) scrollphat.update() time.sleep(.1) time.sleep(.3)
from gpiozero import RGBLED from time import sleep led = RGBLED(red=9, green=10, blue=11) led.red = 1 # full red sleep(1) led.red = 0.5 # half red sleep(1) led.color = (0, 1, 0) # full green sleep(1) led.color = (1, 0, 1) # magenta sleep(1) led.color = (1, 1, 0) # yellow sleep(1) led.color = (0, 1, 1) # cyan sleep(1) led.color = (1, 1, 1) # white sleep(1) led.color = (0, 0, 0) # off sleep(1) # slowly increase intensity of blue for n in range(100): led.blue = n/100 sleep(0.1)
from gpiozero import RGBLED from gpiozero import Button from time import sleep import random from signal import pause import os.path import yaml if ( os.path.isfile('config.yml')): with open("config.yml", "r") as configfile: cfg = yaml.load(configfile) elif ( os.path.isfile('config_orig.yml')): with open("config.yml", "r") as configfile: cfg = yaml.load(configfile) led = RGBLED(red=cfg['red_pin'], green=cfg['green_pin'], blue=cfg['blue_pin']) button = Button(cfg['button_pin']) colors = [ (1,0,0), (0,1,0), (1,1,0), (1,1,1) ] #while True: # led.blink(on_time=1, off_time=1, fade_in_time=1, fade_out_time=1, on_color=random.choice(colors), off_color=(0, 0, 0), n=1, background=False) # sleep(1) while True: led.color = random.choice(colors) sleep(2)
from gpiozero import RGBLED import time led = RGBLED(15, 14, 18) led.color = (0, 0, 1) time.sleep(2) led.off()
sleep(0.1) if new_subscribers - subscribers > 0: red = 1 if new_subscribers % APPLAUSE_THRESHOLD == 0: subprocess.call(["sudo", "omxplayer", "applause.wav"]) else: subprocess.call(["sudo", "omxplayer", "blop.wav"]) sleep(0.1) if new_followers - followers > 0: green = 1 if new_followers % APPLAUSE_THRESHOLD == 0: subprocess.call(["sudo", "omxplayer", "applause.wav"]) else: subprocess.call(["sudo", "omxplayer", "blop.wav"]) sleep(0.1) led.color = (red, green, blue) sleep(1) red = green = blue = 0 led.color = (red, green, blue) likes = new_likes followers = new_followers subscribers = new_subscribers sleep(REFRESH_TIME) # import pygame.mixer # from pygame.mixer import Sound # pygame.mixer.init(48000, -16, 1, 1024) # elec_ping = pygame.mixer.Sound("samples/elec_ping.wav") # elec_ping.play()
buzzer = Buzzer(18) led = RGBLED(red=16, green=20, blue=21, pwm=False) ###### Connect to MongoDB ###### try: conn = pymongo.MongoClient('<insert your mlab endpoint>') db = conn.get_default_database() print("Successfully connected to MongoDB") except pymongo.errors.ConnectionFailure, e: print("Could not connect to MongoDB: {}".format(e)) # MongoDB collections lightsCollection = db['lights'] # Default led to 'off' state led.color = (1, 1, 1) # Function to sound buzzer to represent door bell ringing when visitor presses the arcade button def buzzer_open_door(): buzzer.on() sleep(0.25) buzzer.off() sleep(0.25) buzzer.on() sleep(0.50) buzzer.off() sleep(0.50)
from gpiozero import Button,RGBLED import time button = Button(18) rgbLed = RGBLED(17,27,22) rgbLed.color = (1, 0, 0) ledState = 1 def changeLedState(): global ledState ledState = ledState +1 if (ledState ==0 ): rgbLed.color = (0, 0, 0) elif (ledState ==1 ): rgbLed.color = (1, 0, 0) elif (ledState ==2 ): rgbLed.color = (0, 1, 0) elif (ledState ==3 ): rgbLed.color = (0, 0, 1) ledState = 0 else: rgbLed.color = (1, 1, 1) while True: if button.is_pressed: print("Button is pressed") changeLedState() time.sleep (0.2)
from signal import pause import os.path import yaml if ( os.path.isfile('config.yml')): with open("config.yml", "r") as configfile: cfg = yaml.load(configfile) elif ( os.path.isfile('config_orig.yml')): with open("config.yml", "r") as configfile: cfg = yaml.load(configfile) led = RGBLED(red=cfg['red_pin'], green=cfg['green_pin'], blue=cfg['blue_pin']) button = Button(cfg['button_pin']) state = 'init' led.color = (0,0,1) if ( os.path.isfile('performance.yml')): with open("performance.yml", "r") as configfile: cfg = yaml.load(configfile) elif ( os.path.isfile('performance_orig.yml')): with open("performance.yml", "r") as configfile: cfg = yaml.load(configfile) if cfg['performance'] == "": speed=2 elif cfg['performance'] == "silver": speed=2 elif cfg['performance'] == "gold": speed=1 elif cfg['performance'] == "platinum":
green = DigitalOutputDevice(27) blue = DigitalOutputDevice(22) #TODO: more light relays to control in future? # control buttons #TODO: possible support for multiple light racks in future? apply = Button(21) kill = Button(20) print("PROGRAM ACTIVE") red.off() green.off() blue.off() selectionLED.color = (0, 0, 0) while kill.is_pressed == False: #TODO: add in support for lightRelays1 selectionLED.pulse(1, 1, (0, 0, 1)) #blue blue.on() apply.wait_for_press() selectionLED.off() blue.off() apply.wait_for_release() selectionLED.pulse(1, 1, (0, 1, 0)) #green green.on() apply.wait_for_press() selectionLED.off() green.off() apply.wait_for_release()
from time import sleep from colorsys import hsv_to_rgb from gpiozero import RGBLED from Adafruit_MCP3008 import MCP3008 adc = MCP3008(clk=11, cs=8, miso=9, mosi=10) led = RGBLED(14, 20, 21) JOY_X = 0 # Which pin on the A/D converter JOY_Y = 1 MAX_ANALOG = 1023 MAX_HUE = 950 # Stop at violet (avoid wrapping around to red) try: while True: joy_x = adc.read_adc(JOY_X) joy_y = adc.read_adc(JOY_Y) hue = min(joy_x, MAX_HUE) brightness = MAX_ANALOG - joy_y # Invert so up is brightest hsv = hue / MAX_ANALOG, 1, brightness / MAX_ANALOG # Hue, saturation, value rgb = hsv_to_rgb(*hsv) # Red, green, blue led.color = rgb sleep(1/30) except KeyboardInterrupt: pass led.off()
# * # */ from gpiozero import RGBLED from gpiozero import Button from time import sleep import random from signal import pause import os.path import yaml if (os.path.isfile('config.yml')): with open("config.yml", "r") as configfile: cfg = yaml.load(configfile) elif (os.path.isfile('config_orig.yml')): with open("config.yml", "r") as configfile: cfg = yaml.load(configfile) led = RGBLED(red=cfg['red_pin'], green=cfg['green_pin'], blue=cfg['blue_pin']) button = Button(cfg['button_pin']) colors = [(1, 0, 0), (0, 1, 0), (1, 1, 0), (1, 1, 1)] #while True: # led.blink(on_time=1, off_time=1, fade_in_time=1, fade_out_time=1, on_color=random.choice(colors), off_color=(0, 0, 0), n=1, background=False) # sleep(1) while True: led.color = random.choice(colors) sleep(2)
from gpiozero import RGBLED from time import sleep print(__name__) colors = [(1, 0, 0), (1, 1, 0), (1, 0, 1), (0, 1, 0), (0, 1, 1), (0, 0, 1), (1, 1, 1)] if __name__ == '__main__': print('run') #it is within the if tap, need to block behind the "if" command rgbled = RGBLED(17, 27, 22) #this is a tuple while True: #while True command creates a loop #print('run'); #rgbled.color=(1,0,0); #sleep(1); #rgbled.color=(0,1,0); #sleep(1); #rgbled.color=(0,0,1); #sleep(1); for color in colors: rgbled.color = color sleep(1)
camera.annotate_background = Color('black') camera.annotate_text_size = 16 camera.vflip = True start = time.time() #camera.start_preview() filename = video_dir+'dashcam_'+datetime.now().strftime('%Y-%m-%d_%H.%M.%S')+'.h264' videos = deque([filename]) camera.start_recording(filename,format='h264',resize=(vid_width,vid_height)) rec_button = Button(4) stop_button = Button(25) rec_button.when_pressed = recbuttonpress stop_button.when_pressed = stopbuttonpress led = RGBLED(27,8,17) while not camera.closed: led.color = (1,0,1) if not shutdown: end = time.time() seconds = end - start camera.annotate_text = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if save == True: save = False print "Saving video" filename = video_dir+'dashcam_'+datetime.now().strftime('%Y-%m-%d_%H.%M.%S')+'.h264' camera.split_recording(filename) dst = video_store+datetime.now().strftime('%Y')+'/'+datetime.now().strftime('%b')+'/'+datetime.now().strftime('%d')+'/' if not os.path.exists(dst): os.makedirs(dst) for i in range(len(videos)): src = videos.popleft()
from threading import Event from colorzero import Color from gpiozero import RotaryEncoder, RGBLED, Button rotor = RotaryEncoder(16, 20, wrap=True, max_steps=180) rotor.steps = -180 led = RGBLED(22, 23, 24, active_high=False) btn = Button(21, pull_up=False) led.color = Color('#f00') done = Event() def change_hue(): # Scale the rotor steps (-180..180) to 0..1 hue = (rotor.steps + 180) / 360 led.color = Color(h=hue, s=1, v=1) def show_color(): print('Hue {led.color.hue.deg:.1f}° = {led.color.html}'.format(led=led)) def stop_script(): print('Exiting') done.set() print('Select a color by turning the knob') rotor.when_rotated = change_hue print('Push the button to see the HTML code for the color') btn.when_released = show_color
from Adafruit_BME280 import * from time import sleep from gpiozero import RGBLED sensor = BME280(mode=BME280_OSAMPLE_8) led = RGBLED(red=4, green=26, blue=19) start_temp = False counter = 0 while True: degrees = sensor.read_temperature() pascals = sensor.read_pressure() hectopascals = pascals / 100 humidity = sensor.read_humidity() print 'Timestamp = {0:0.3f}'.format(sensor.t_fine) print 'Temp = {0:0.3f} deg C'.format(degrees) print 'Pressure = {0:0.2f} hPa'.format(hectopascals) print 'Humidity = {0:0.2f} %'.format(humidity) print ' ' if not start_temp and counter>3: start_temp = degrees counter += 1 diff_temp = max(0, min(1, (degrees-start_temp))) #print(diff_temp) led.color = (diff_temp, 0,1-diff_temp) sleep(0.02)
from gpiozero import RGBLED from time import sleep if __name__ == '__main__': # initialize the gpio pin rgbled = RGBLED(12, 20, 21) #(r,g,b) rgb_color = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, 0)] i = 0 mode = len(rgb_color) - 1 while (i < mode * 5): ## print(i) rgbled.color = rgb_color[i % mode] sleep(1) i += 1 # turn off led rgbled.color = rgb_color[mode]
help="minimum probability to filter weak detections") args = vars(ap.parse_args()) # load our serialized model from disk print("[INFO] loading model...") net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"]) # initialize the video stream and allow the cammera sensor to warmup print("[INFO] starting video stream...") vs = VideoStream(src=0).start() time.sleep(2.0) # loop over the frames from the video stream while True: isFace = False left_eye.color = color right_eye.color = color # grab the frame from the threaded video stream and resize it # to have a maximum width of 400 pixels frame = vs.read() frame = imutils.resize(frame, width=400) # grab the frame dimensions and convert it to a blob (h, w) = frame.shape[:2] blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)), 1.0, (300, 300), (104.0, 177.0, 123.0)) # pass the blob through the network and obtain the detections and # predictions net.setInput(blob) detections = net.forward()
from gpiozero import RGBLED import psutil, time myled = RGBLED(14,15,18) while True: cpu = psutil.cpu_percent() r = cpu / 100.0 g = (100 - cpu)/100.0 b = 0 myled.color = (r, g, b) time.sleep(0.1)
# GPIOZERO_PIN_FACTORY=pigpio PIGPIO_ADDR=192.168.4.158 from gpiozero import RGBLED, Button from time import sleep from signal import pause from gpiozero.pins.pigpio import PiGPIOFactory from random import random pi_host = '192.168.4.158' factory = PiGPIOFactory(host=pi_host) led = RGBLED(22, 27, 17, pin_factory=factory) button_white = Button(26, pin_factory=factory) while True: if button_white.is_pressed: break red_value = random() green_value = random() blue_value = random() led.color = (red_value, green_value, blue_value) sleep(0.5) led.color = (0, 0, 0)
def main(): print("=============================================================================") infura_url = "https://ropsten.infura.io/v3/e08b40808f684eb19d87cc56a1effb58" w3 = Web3(Web3.HTTPProvider(infura_url)) if w3.isConnected(): print("Successfully connected to Infura") else: print("Failed to connect to Infura, please check your network") return button = Button(2) sensor = adafruit_dht.DHT22(board.D14) codes = ((0,0,0),(0,0,1),(0,1,0),(0,1,1),(1,0,0),(1,0,1),(1,1,0),(1,1,1)) colors = ("off","blue","red","cyan","green","magenta","yellow","white") led = RGBLED(red=9, green=10, blue=11) led.color = codes[7] print("The initial led color is white") print("Setting gas price strategy. Please wait...") w3.eth.setGasPriceStrategy(fast_gas_price_strategy) gas_price = w3.eth.generateGasPrice() print("Estimated gas price {} gwei".format(Web3.fromWei(gas_price, "gwei"))) contract_address = "0xb9878c7554Ffd73B6f89cF2C95b4DC2a2aBA0Ba4" abi = json.loads('[ { "constant": false, "inputs": [ { "internalType": "bytes", "name": "time", "type": "bytes" }, { "internalType": "bytes", "name": "temp", "type": "bytes" }, { "internalType": "bytes", "name": "hum", "type": "bytes" } ], "name": "add_records", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "_to", "type": "address" }, { "internalType": "uint8", "name": "color", "type": "uint8" } ], "name": "control_led", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [], "name": "destory", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "_from", "type": "address" }, { "indexed": true, "internalType": "address", "name": "_to", "type": "address" }, { "indexed": false, "internalType": "uint8", "name": "color", "type": "uint8" } ], "name": "led", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "_from", "type": "address" }, { "indexed": false, "internalType": "bytes", "name": "time", "type": "bytes" }, { "indexed": false, "internalType": "bytes", "name": "temp", "type": "bytes" }, { "indexed": false, "internalType": "bytes", "name": "hum", "type": "bytes" } ], "name": "records", "type": "event" } ]') account_address = "0x89271f3D30A6C5c7B29df718D00d93c924e58D1F" private_key = "7106B9FA0663727B1DEC493FE77DC4F303614F0E2D62EE527FC8A4AFB463463E" contract = w3.eth.contract(address=contract_address, abi=abi) event_filter = contract.events.led.createFilter(fromBlock="latest", argument_filters={"_to": account_address}) print("=============================================================================") def encode(x): return str(x).encode() def send_tx(): try: timestamp = time.asctime() temperature = sensor.temperature humidity = sensor.humidity print("{} Temperature:{}C Humidity:{}%".format(timestamp, temperature, humidity)) print("-----------------------------------------------------------------------------") except RuntimeError as error: print("Failed to get temperature and humidity. Please try again...") print(error) print("=============================================================================") return timestamp_encode = encode(timestamp) temperature_encode = encode(temperature) humidity_encode = encode(humidity) nonce = w3.eth.getTransactionCount(account_address) function = contract.functions.add_records(timestamp_encode, temperature_encode, humidity_encode) tx = function.buildTransaction({"nonce": nonce}) print("Transaction:") print(tx) print("-----------------------------------------------------------------------------") try: signed_tx = w3.eth.account.signTransaction(tx, private_key) tx_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction) receipt = w3.eth.waitForTransactionReceipt(tx_hash) print("Successfully sent to Ethereum") print("gas used:", receipt.cumulativeGasUsed) print("contract address:", contract_address) print("tx:", Web3.toHex(receipt.transactionHash)) print("block:", Web3.toHex(receipt.blockHash)) except Exception as e: print(e) print("=============================================================================") while True: for event in event_filter.get_new_entries(): color = event.args.color print("Changed led color to", colors[color]) led.color = codes[color] print("from:", event.args._from) print("tx:", Web3.toHex(event.transactionHash)) print("block:", Web3.toHex(event.blockHash)) print("=============================================================================") button.when_pressed = send_tx time.sleep(1)
# code to run LEDs with Rangefinder from gpiozero import PWMLED, RGBLED, DistanceSensor import time singleLED = PWMLED(14) rgbLED = RGBLED(16, 20, 21) rangefind = DistanceSensor(24, 18) # Test the LEDs # turn on the RGB LED rgbLED.color = (1, 0, 0) # red time.sleep(1) rgbLED.color = (0, 1, 0) # green time.sleep(1) rgbLED.color = (0, 0, 1) # blue time.sleep(1) rgbLED.color = (1, 1, 1) # bright white time.sleep(1) rgbLED.color = (.01, .01, .01) # dim white time.sleep(1) rgbLED.off() # turn on LED singleLED.value = .01 # dim time.sleep(1) singleLED.value = 1 # bright time.sleep(1) singleLED.off()
from gpiozero import RGBLED, Buzzer import time rgb = RGBLED(red=21, green=20, blue=19) buzzer = Buzzer(18) rgb.color = (0, 1, 0) buzzer.off() time.sleep(2) rgb.color = (1, 0, 0) time.sleep(2) rgb.color = (1, 1, 0) time.sleep(2) rgb.color = (1, 1, 1)
# From the code for the Box 1 kit for the Raspberry Pi by MonkMakes.com from gpiozero import Button, RGBLED from colorzero import Color import time, requests update_period = 10 # seconds led = RGBLED(red=18, green=23, blue=24) button = Button(25) cheerlights_url = "http://api.thingspeak.com/channels/1417/field/2/last.txt" old_color = None def pressed(): led.color = Color(0, 0, 0) # LED off button.when_pressed = pressed while True: try: cheerlights = requests.get(cheerlights_url) color = cheerlights.content # the color as text if color != old_color: led.color = Color(color) # the color as an object old_color = color except Exception as e: print(e) time.sleep(update_period) # don't flood the web service
from gpiozero import RGBLED from time import sleep led = RGBLED(red=25, green=12, blue=21) led.red = 1 sleep(1) led.red = 0.5 sleep(1) led.color = (0, 1, 0) sleep(1) led.color = (1, 0, 1) sleep(1) led.color = (1, 1, 0) sleep(1) led.color = (0, 1, 1) sleep(1) led.color = (1, 1, 1) sleep(1) led.color = (0, 0, 0) sleep(1) for n in range(100): led.blue = n / 100 #print(n/100) sleep(0.1)
from gpiozero import RGBLED from time import sleep led = RGBLED(17, 18, 27, active_high=False) #(R,G,B) led.color = (1, 0, 0) #red print("red") sleep(1) led.color = (0, 1, 0) #green print("green") sleep(1) led.color = (0, 0, 1) #blue print("blue") sleep(1) led.color = (1, 0, 1) #purple print("purple") sleep(1) led.color = (1, 1, 0) #light green print("light green") led.off()
from gpiozero import RGBLED from time import sleep led = RGBLED(red=9, green=10, blue=11) led.red = 1 #full red sleep(1) led.red = 0.5 #half red sleep(1) led.color = (0, 1, 0) # full green sleep(1) led.color = (1, 0, 1) #magenta sleep(1) led.color = (1, 1, 0) #yellow sleep(1) led.color = (0, 1, 1) #cyan sleep(1) led.color = (1, 1, 1) #white sleep(1) led.color = (0, 0, 0) #off sleep(1) # slowly increase intensity of blue for n in range(100): led.blue = n / 100 sleep(0.1)
from gpiozero import RGBLED import psutil, colorsys, time myled = RGBLED(14,18,15) while True: cpu = psutil.cpu_percent() r = cpu / 100.0 g = (100 - cpu)/100.0 b = 0 myled.color = (r,g,b) time.sleep(0.1)