Vettehra
Posts: 1
Joined: Mon Aug 15, 2016 6:12 pm

Code debugging, Please help, led control by date

Mon Aug 15, 2016 6:17 pm

Hello, I was trying to write a code, witch would controll leds by date.
But I don't understand, why that little led don't whant to listen me :D
Theres a code:

Code: Select all

import sys
import time
import datetime
import RPi.GPIO as GPIO
import SDL_DS1307


#===============LED OUTPUTS==============
LED_R = 17
LED_G = 18
LED_B = 27

#=============PINS OPTIONS============
GPIO.setup(LED_R, GPIO.OUT)
GPIO.setup(LED_G, GPIO.OUT)
GPIO.setup(LED_B, GPIO.OUT)

#================COLOURS==================
RED=[LED_R]
GREEN=[LED_G]
BLUE=[LED_B]
CYAN=[LED_G,LED_B]
MAGENTA=[LED_R,LED_B]
YELLOW=[LED_R,LED_G]
WHITE=[LED_R,LED_G,LED_B]
#==========================================

filename = time.strftime("%Y-%m-%d%H:%M:%SRTCTest") + ".txt"
starttime = datetime.datetime.utcnow()

ds1307 = SDL_DS1307.SDL_DS1307(1, 0x68)
ds1307.write_now()

while True:
	currenttime = datetime.datetime.utcnow()
	deltatime = currenttime - starttime
        data=time.strftime("%Y"+"%m"+"%d"+"%H"+"%M")
	time.sleep(10.0)
            with open('data.txt') as f:
                    for line in f:
                        parts=line.split()
                        if parts[0]<=(data)<=parts[1]:
                            if parts[2]=='100':
                                colour[RED, True]
                            if parts[2]=='010':
                                colour[GREEN, True]
                            if parts[2]=='001':
                                colour[BLUE, True]
                            if parts[2]=='110':
                                colour[MAGENTA, True]
                            if parts[2]=='011':
                                colour[CYAN, True]
                            if parts[2]=='101':
                                colour[YELLOW, True]
                            if parts[2]=='111':
                                colour[WHITE, True]
with turned off gpio warnings raspberry says that these pins are already in use
Sorry for my poor gramma :)

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Code debugging, Please help, led control by date

Tue Aug 16, 2016 5:24 pm

What is this meant to do?

Code: Select all

colour[RED, True]
And add this before you set up the pins

Code: Select all

GPIO.setmode(GPIO.BCM)
Dave.
Apple say... Monkey do !!

User avatar
bensimmo
Posts: 4654
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Code debugging, Please help, led control by date

Tue Aug 16, 2016 6:56 pm

As above 'colours' is not defined ?


Anyway, have you thought about using the (built into full raspian) GPIOZERO
https://gpiozero.readthedocs.io/en/v1.2 ... ml#rgb-led

Return to “Python”