The programme works in the terminal but when I try to run it automatically the boot won't load the programme past the second line in the main while loop. addstar = input() giving the EOFError:when reading a line
The input is from a usb NFC tag reader which acts like a keyboard. The programme depends on the tag value.
A 'words of one syllable advice would be so appreciated'
Code: Select all
!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
#_IP=$(hostname -I) || true
#if [ "$_IP" ]; then
# printf "My IP address is %s\n" "$_IP"
#fi
python3 /home/pi/starbox/starbox.py &
exit 0
starbox.py
Code: Select all
#A programme for giving a child merit stars
import os
import time
import board
import busio as io
from adafruit_motorkit import MotorKit
from adafruit_motor import stepper
from adafruit_servokit import ServoKit
from adafruit_ht16k33 import segments
i2c = io.I2C(board.SCL, board.SDA)
def openwindow():
kit = ServoKit(channels=16)
kit.continuous_servo[1].throttle = -1
kit.servo[0].angle = 0
kit.continuous_servo[1].throttle = 0
def closewindow():
kit = ServoKit(channels=16)
kit.continuous_servo[1].throttle = 1
kit.servo[0].angle = 110
kit.continuous_servo[1].throttle = 0
def paperscroll():
motorkit = MotorKit()
for i in range(1000):
motorkit.stepper1.onestep(style = stepper.SINGLE)
time.sleep(0.001)
motorkit.stepper1.release()
# papercount = 0
def addstarfunction():
# default to adding just one star
addstar = "0007363189"
# get the existing no of stars and how many on the current row
f1 = open("/home/pi/starbox/starcount.txt", "r")
starcount = int(f1.read())
f1.close()
f2=open("/home/pi/starbox/linetotal.txt","r")
linecount = int(f2.read())
f2.close()
print(linecount)
print (starcount)
# start and fill the display
counter = segments.Seg14x4(i2c,address=0x74)
counter.fill(0)
counter.brightness = .1
counter.print(str(starcount)
# main input loop
while addstar != "0006742580":# safety check ...580 exits
addstar = input()
counter = segments.Seg14x4(i2c,address=0x74)
counter.fill(0)
counter.brightness = 1.0
message = "ADD STARS UP TO A TOTAL OF 10 IN THE ROW AND PRESENT THE TAG AGAIN"
count = 0
while count < len(message):
counter.print(message[count])
count += 1
time.sleep(0.2)
counter.fill(0)
counter.print(starcount)
print("input 1")
if addstar == "0007363189":#add one star to the total. The user should stick one star to the paper
openwindow()
#wait until the star has been stuck on then present the tag again
addstar = input()
starcount +=1
linecount +=1
# closewindow(kit)#close the window
elif addstar == "0006734896":#add two stars to the total. The user should stick two stars to the paper
openwindow()
#wait until the star has been stuck on then present the tag again
addstar = input()
starcount +=2
linecount +=2
elif addstar == "0006633466":#add 3 stars to the total. The user should stick three stars to the paper
openwindow()
#wait until the star has been stuck on then present the tag again
addstar = input()
print("input 2")
starcount +=3
linecount +=3
elif addstar == "0006653112": # If a star is taken away we don't take one off the papercount or it will scroll in the wrong place
starcount -=1
elif addstar == "0006742580":
exit()
if linecount ==10:
linecount = 0
paperscroll()
if linecount > 10:
linecount=0
counter.fill(0)
message = "WAIT UNTIL THE PAPER HAS STOPPED MOVING, ADD THE EXTRA STARS AND PRESENT THE TAG AGAIN"
count = 0
while count < len(message):
counter.print(message[count])
count += 1
time.sleep(0.2)
counter.fill(0)
paperscroll()
addstar = input() #let more stars be stuck on
print("input3")
closewindow()#close the window
#write the new values to files
f1=open("/home/pi/starbox/starcount.txt","w")
f1.write(str(starcount))
f1.close()
f2=open("/home/pi/starbox/linetotal.txt","w")
f2.write(str(linecount))
f2.close()
# start the counter display
counter.brightness = 1.0
counter.fill(0)
message = "EDDIE YOU NOW HAVE " +str(starcount)+ " STARS"
count = 0
while count < len(message):
counter.print(message[count])
count += 1
time.sleep(0.2)
counter.fill(0)
counter.brightness = .1
counter.print(str(starcount))
print(linecount)
print (str(starcount))
addstarfunction()