Skip to content

Instantly share code, notes, and snippets.

@aula9
Created May 28, 2019 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aula9/69473ef635e3f8610dcc36815116b4f4 to your computer and use it in GitHub Desktop.
Save aula9/69473ef635e3f8610dcc36815116b4f4 to your computer and use it in GitHub Desktop.
import time
import Adafruit_TCS34725
import smbus
import RPi.GPIO as GPIO
import turtle
tcs = Adafruit_TCS34725.TCS34725()
tcs.set_interrupt(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(32, GPIO.OUT)
GPIO.setup(36, GPIO.OUT)
GPIO.setup(38, GPIO.OUT)
pr = GPIO.PWM(32,50)
pg = GPIO.PWM(36,50)
pb = GPIO.PWM(38,50)
pr.start(20)
pg.start(20)
pb.start(20)
i =0
w=" "
while i <10:
i =i+1
r, g, b, c = tcs.get_raw_data()
color_temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b)
lux = Adafruit_TCS34725.calculate_lux(r, g, b)
print('Color: red={0} green={1} blue={2} clear={3}'.format(r, g, b, c))
time.sleep(1)
if((r > b) and (r >g)):
if(b <5):
pr.ChangeDutyCycle(80)
pg.ChangeDutyCycle(1)
pb.ChangeDutyCycle(1)
w="red"
print(w)
elif (r-g <20 and r-b > 10 and r>15):
pr.ChangeDutyCycle(80)
pg.ChangeDutyCycle(65)
pb.ChangeDutyCycle(1)
w="yellow"
print(w)
elif((r < b) and (b >5)):
pr.ChangeDutyCycle(1)
pg.ChangeDutyCycle(1)
pb.ChangeDutyCycle(80)
w="blue"
print(w)
elif((r < g) and (b <g) and (g>20)):
if (b<10):
pr.ChangeDutyCycle(1)
pg.ChangeDutyCycle(80)
pb.ChangeDutyCycle(1)
w="green"
print(w)
elif(b>10 and r-g <6):
pr.ChangeDutyCycle(60)
pg.ChangeDutyCycle(5)
pb.ChangeDutyCycle(70)
w="purple"
print(w)
elif((r > g) and (b > g) and (r>45)):
pr.ChangeDutyCycle(0)
pg.ChangeDutyCycle(70)
pb.ChangeDutyCycle(70)
w="cyan"
print(w)
elif((r > 100) and (b > 90) and (g> 100)):
pr.ChangeDutyCycle(0)
pg.ChangeDutyCycle(70)
pb.ChangeDutyCycle(70)
w="white"
print(w)
#elif((r < 25) and (b <20) and (g < 20)):
#pr.ChangeDutyCycle(0)
#pg.ChangeDutyCycle(0)
#pb.ChangeDutyCycle(0)
#w="black"
#print(w)
else:
pr.ChangeDutyCycle(20)
pg.ChangeDutyCycle(20)
pb.ChangeDutyCycle(20)
time.sleep(9)
trtl = turtle.Turtle() #making a turtle object of Turtle class for drawing
screen=turtle.Screen() #making a canvas for drawing
screen.setup(400,300) #choosing the screen size
screen.bgcolor('black') #making canvas black
trtl.pencolor(w) #making colour of the pen red
trtl.pensize(5) #choosing the size of pen nib
trtl.speed(1) #choosing the speed of drawing
trtl.shape('turtle') #choosing the shape of pen nib
trtl.forward(100) #top line
trtl.right(90)
trtl.forward(100) # right vertical line
trtl.right(90)
trtl.forward(100) # bottom line
trtl.right(90)
trtl.forward(100) # left vertical line
# information printing
trtl.penup()
trtl.setpos(-120,100)
trtl.pendown()
trtl.pencolor(w)
trtl.write(w, font=("Arial", 16, "bold"))
trtl.penup()
trtl.ht()
# Print out color temperature.
#if color_temp is None:
# print('Too dark to determine color temperature!')
#else:
# print('Color Temperature: {0} K'.format(color_temp))
#print('Luminosity: {0} lux'.format(lux))
tcs.set_interrupt(True)
tcs.disable()
pr.stop()
pg.stop()
pb.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment