1

Fixed code again, now leds working as they have to, i don't know why all Trues and Falses are upside down, because, where should be True is False and vice versa.

But there is one problem: if leds were turned on by earlier and don't have to glow by condition, they won't turn off until starts other (new) condition when they have to turn on. Where is the problem?

import sys
import time
import datetime
import RPi.GPIO as GPIO
import SDL_DS1307
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
LED_R = 17
LED_G = 27
LED_B = 22
GPIO.setup(17, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
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")
 
 with open('data.txt') as f:
 for line in f:
 parts=line.split() 
 if parts[0]<=(data)<=parts[1]:
 if parts[2]=='100':
 GPIO.putput(LED_R, False)
 GPIO.putput(LED_G, True)
 GPIO.putput(LED_B, True)
 elif parts[2]=='010':
 GPIO.putput(LED_R, True)
 GPIO.putput(LED_G, False)
 GPIO.putput(LED_B, True)
 elif parts[2]=='001':
 GPIO.putput(LED_R, True)
 GPIO.putput(LED_G, True)
 GPIO.putput(LED_B, False)
 elif parts[2]=='110':
 GPIO.putput(LED_R, False)
 GPIO.putput(LED_G, True)
 GPIO.putput(LED_B, False) 
 elif parts[2]=='101':
 GPIO.putput(LED_R, True)
 GPIO.putput(LED_G, False)
 GPIO.putput(LED_B, False)
 elif parts[2]=='101':
 GPIO.putput(LED_R, False)
 GPIO.putput(LED_G, False)
 GPIO.putput(LED_B, True)
 elif parts[2]=='111':
 GPIO.putput(LED_R, False)
 GPIO.putput(LED_G, False)
 GPIO.putput(LED_B, False)
 else:
 GPIO.output(LED_R, True)
 GPIO.output(LED_G, True)
 GPIO.output(LED_B, True)
 time.sleep(1.0)
4
  • You have defined LED_R G B as 17 27 22. Why do you still use 17 27 22 in your following lines? Who was your programming teacher? Commented Aug 18, 2016 at 20:46
  • Google, was my teacher Commented Aug 19, 2016 at 18:21
  • If you replace all numbers by the LED_x equivalent, you should see the error. Commented Aug 19, 2016 at 18:23
  • I have corrected the code, 17, 22, 27 was replaced by LER_R, LED_G, LED_B , but all the same as was, i don't know, how to edit the code, if time is ended leds turns off, because, when if ends leds still on, they have to turn off, but how? Commented Aug 19, 2016 at 18:38

2 Answers 2

1

You are calling GPIO.cleanup immediately after writing to the LEDs. That switches all the GPIO you are using to be inputs rather than outputs.

I am surprised you don't get error messages when you run the code. Perhaps the GPIO.setwarnings call is hiding the errors.

The simplest fix is to delete the GPIO.cleanup line.

answered Aug 16, 2016 at 15:26
5
  • Deleting GPIO.cleanup() won't help After that i enabled error messages, raspi says: 'RuntimeWarning: This channel is already in use...' Commented Aug 16, 2016 at 15:30
  • Also looks like a typo in the last line, it says PIO.output(17, 21, 22, True) and should probably be GPIO.output(...). Commented Aug 16, 2016 at 15:31
  • my fault :D Fixed Commented Aug 16, 2016 at 15:34
  • But still not working :/ Commented Aug 16, 2016 at 15:40
  • 1
    You need to edit your question and say what isn't working. No point in us guessing. Commented Aug 16, 2016 at 16:03
1

You read through each line of a file, turning on various LEDs, but each loop happens so fast that you barely see anything happen. You need to move your sleep statement.

you can put it here:

for line in f:
 time.sleep(1.0)

...or better yet, put it at the very bottom of the for() loop so it sleeps after the line is processed. It should be indented only once inside the loop.

answered Aug 17, 2016 at 19:26
1
  • Thats not working, mabie better use 'while' than 'if' in first 'if' line? Commented Aug 18, 2016 at 16:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.