예제 #1
0
def recv_ws_con_q_handle(data,ws):
	recv_ws_con_q.append((data,ws));
	
	arduino = arduino_bridge.connection()
	arduino.setup_digital_output(13) #left
	arduino.setup_digital_output(14) #right
	arduino.setup_pwm_output(0) # right pwm
	arduino.setup_pwm_output(9) # left pwm 
예제 #2
0
import arduino_bridge
import time

pin=1
value=122

arduino = arduino_bridge.connection()
arduino.setup_pwm_output(pin)

for i in range(0,25):
	arduino.setPWM(pin,i*10)
	time.sleep(0.05)
	print("GPIO pin "+str(pin)+" set duty cycle to "+str(i))
예제 #3
0
파일: demo.py 프로젝트: WarLion/CHIP_SALSA
import arduino_bridge
import time

print("SALSA DEMO SCRIPT")
print("")
salsa = arduino_bridge.connection()

#-----------------------------------------------------------------------------------------#
print("Lets do a fancy lightshow:")
print("Do you have a few ws2812 in a string? ")
print("This demo will use 24, but it doesn't really matter if you have")
print("more or less connected. Connect the power to the Vcc pin on the SALSA")
print("GND to GND and the ws2812 Data in pin to P6")

usr_in = "a"
while str.lower(usr_in) != "y" and str.lower(usr_in) != "s" and str.lower(
        usr_in) != "o":
    usr_in = input("Ready? (yes = y, skip = s, use onboard ws2812 = o)")

if str.lower(usr_in) == "y" or str.lower(usr_in) == "o":
    print("running")
    LC = 24
    ROUNDS = 40
    DELAY = 0.02
    pin = 6
    if str.lower(usr_in) == "o":
        pin = 7

    salsa.setup_ws2812_unique_color_output(pin, LC)

    # create a color array, rainbow for demonstration
예제 #4
0
sec_bin=bytearray(6)

# prepare vars
pin = 6
LC = 38	# spinach dip has 38 leds
with_date = 1
with_temp = 0
offset = 4
dimm_value = 60 # divide by 15
on_value = 60

if(with_temp and with_date):
	exit("only date OR temperature")

# setup salsa
salsa = arduino_bridge.connection()
salsa.setup_ws2812_unique_color_output(pin,LC)

colorArray = [arduino_bridge.Color(0,0,0) for i in range(LC)]

while 1:
	# generate color, shall be dynamic later therefor in loop
	temp_max_color = arduino_bridge.Color(on_value, 0, 0) # red
	temp_min_color = arduino_bridge.Color(0, 0, on_value) # blue
	month_color = arduino_bridge.Color(on_value, 0, 0)	 # red
	day_color = arduino_bridge.Color(on_value, on_value//2, 0)	 # orange
	hour_color = arduino_bridge.Color(0, 0, on_value)	 # blue
	min_color = arduino_bridge.Color(on_value, 0, on_value)	 # pink
	sec_color = arduino_bridge.Color(0, on_value, 0)	 # green	

	# generate bin array for time, date and temp
예제 #5
0
파일: light.py 프로젝트: pdf7/illuminum
	def run(self,config):		
		self.config = config

		while(1):
			p.rint("LIGHT, thread started","l")
			self.alive = True


			# Create NeoPixel object with appropriate configuration.
			if(str(self.config.with_lights) == "1"):
				p.rint("LIGHT, configured with NEO usage","l")
				if(self.neo_support and self.neo_loaded!=1):
					p.rint("LIGHT, neopixel supported, starting","l")
					strip = Adafruit_NeoPixel(self.neo_LED_COUNT, self.neo_LED_PIN, self.neo_LED_FREQ_HZ, self.neo_LED_DMA, self.neo_LED_INVERT, self.neo_LED_BRIGHTNESS)
					# Intialize the library (must be called once before other functions).
					strip.begin()
					strip.show()
					self.neo_loaded = 1 	# avoid loading it twice
				elif(self.neo_support):
					p.rint("LIGHT, neopixel already loaded","l")
				else:
					p.rint("LIGHT, ERROR neopixel not supported","l")
			elif(str(self.config.with_lights) == "2"):
				p.rint("LIGHT, configured with PWM usage","l")
				if(self.pwm_support):
					p.rint("LIGHT, PWM supported, starting","l")
					wiringpi.wiringPiSetupPhys()
					wiringpi.pinMode(12,2)
				else:
					p.rint("LIGHT, ERROR PWM not supported","l")
			elif(str(self.config.with_lights) == "3"):
				p.rint("LIGHT, configured with i2c usage","l")
				if(self.i2c_support and self.i2c_loaded!=1):
					p.rint("LIGHT, i2c supported, starting","l")
					salsa = arduino_bridge.connection()
					salsa.setup_pwm_output(0)
					salsa.setup_pwm_output(1)
					salsa.setup_pwm_output(2)
					salsa.setup_pwm_output(3)
					self.i2c_loaded = 1
				elif(self.i2c_loaded == 1):
					p.rint("LIGHT, i2c already loaded","l")
				else:
					p.rint("LIGHT, ERROR i2c not supported","l")
			else:
				p.rint("LIGHT, started without pwm and neo and i2c","l")
				p.rint("LIGHT, selection was "+str(self.config.with_lights),"l")

			while self.alive:
				### ------------ check if we have something to do ------------ ###
				if(len(self.light_dimming_q) > 0):
					for data in self.light_dimming_q:
						if(data[0]<=time.time()):
							light_action=data
							self.light_dimming_q.remove(data)
							if(light_action[1]==-1 and light_action[2]==-1 and light_action[3]==-1):
								self.return_to_old(light_action[4])
							else:
								self.dimm_to(light_action[1],light_action[2],light_action[3],light_action[4])
				### ------------ check if we have something to do ------------ ###

				if(self.l.state==1):						# state= 1 means dimming is active
					if(time.time()>=self.l.last_ts+self.l.ms_step/1000):	# last_ts holds time of last event, ms_step the time between two dimm steps, 
											# if that sum is smaller than NOW - we have work
						self.l.last_ts=time.time()			# refresh last_ts to now
						differ_r=self.l.s_r-self.l.t_r			# caluclate the difference of each color between the start and the end color
						differ_g=self.l.s_g-self.l.t_g
						differ_b=self.l.s_b-self.l.t_b
						differ_time=(self.l.t_t-self.l.s_t)		# calulate the total time between the start and end 
											#(this should be the same as the "dimm time" specified by the user)
						if(differ_time>0):			# if the user set instant switch, this time will be 0. avoid division by zero
							ratio=(time.time()-self.l.s_t)/(self.l.t_t-self.l.s_t)	# ratio of the time that has passed, should be 0..1
						else:
							ratio=1
						if(ratio<1):				# if ratio is below 1 we are still in the middle of the dimming
							if(LED_DEBUG):
								print(".", end="")
							self.l.c_r=int(self.l.s_r-ratio*differ_r)	# refresh the r,g,b parts to the current dimm ratio (minus since we did a "self.l.s_r - self.l.t_r")
							self.l.c_g=int(self.l.s_g-ratio*differ_g)
							self.l.c_b=int(self.l.s_b-ratio*differ_b)

						else:					# ratio is bigger than one, time has passed, set it to target color
							self.l.c_r=int(self.l.t_r)
							self.l.c_g=int(self.l.t_g)
							self.l.c_b=int(self.l.t_b)
							self.l.state=0 			# stop further dimming
							if(LED_DEBUG):
								print("LED stop at "+str(time.time())+" "+str(self.l.c_r)+"/"+str(self.l.c_g)+"/"+str(self.l.c_b))


						self.l.c_r=max(min(255,self.l.c_r),0)		# avoid that we set a value bigger then 255 or smaller then 0
						self.l.c_g=max(min(255,self.l.c_g),0)
						self.l.c_b=max(min(255,self.l.c_b),0)

						# neo pixel
						if(str(self.config.with_lights) == "1" and self.neo_support):
							for i in range(0,self.neo_LED_COUNT):
								strip.setPixelColor(i,Color(self.l.c_r,self.l.c_g,self.l.c_b))		# set value
							strip.show()
						# neo pixel
						# pwm controll on pin 12
						elif(str(self.config.with_lights) == "2" and self.pwm_support):
							wiringpi.pwmWrite(12, self.l.c_r*4)
						# pwm controll on pin 12
						# i2c controll
						elif(str(self.config.with_lights) == "3" and self.i2c_support):
							try:
								print(str(self.l.c_b))
								salsa.dimmTo(0,int(self.l.c_r/2.55),10) #  dimming is in % #R
								salsa.dimmTo(1,int(self.l.c_g/2.55),10) #  dimming is in % #G
								salsa.dimmTo(2,int(self.l.c_b/2.55),10) #  dimming is in % #B
								salsa.dimmTo(3,int(self.l.c_b/2.55),10) #  dimming is in % #B

							except:
								print("LIGHT i2c bus transaction crashed")
						# i2c controll

						# we can wait here a little while because we know that nothing will happen for us earlier than that anyway
						time.sleep(0.8*self.l.ms_step/1000) 		

				else:
					time.sleep(0.01) # sleep to avoid 100% cpu
				# while
		p.rint("LIGHT, thread stopped","l")