freenove_car/Code/Server/test.py

157 lines
4.7 KiB
Python
Raw Normal View History

2019-09-24 21:09:34 -04:00
import time
from Led import *
led=Led()
def test_Led():
try:
led.ledIndex(0x01,255,0,0) #Red
led.ledIndex(0x02,255,125,0) #orange
led.ledIndex(0x04,255,255,0) #yellow
led.ledIndex(0x08,0,255,0) #green
led.ledIndex(0x10,0,255,255) #cyan-blue
led.ledIndex(0x20,0,0,255) #blue
led.ledIndex(0x40,128,0,128) #purple
led.ledIndex(0x80,255,255,255) #white'''
2020-03-03 04:39:01 -05:00
print ("The LED has been lit, the color is red orange yellow green cyan-blue blue white")
2019-09-24 21:09:34 -04:00
time.sleep(3) #wait 3s
led.colorWipe(led.strip, Color(0,0,0)) #turn off the light
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2019-09-24 21:09:34 -04:00
except KeyboardInterrupt:
led.colorWipe(led.strip, Color(0,0,0)) #turn off the light
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2019-09-24 21:09:34 -04:00
from Motor import *
PWM=Motor()
def test_Motor():
try:
PWM.setMotorModel(1000,1000,1000,1000) #Forward
2020-03-03 04:39:01 -05:00
print ("The car is moving forward")
2019-09-24 21:09:34 -04:00
time.sleep(1)
PWM.setMotorModel(-1000,-1000,-1000,-1000) #Back
2020-03-03 04:39:01 -05:00
print ("The car is going backwards")
2019-09-24 21:09:34 -04:00
time.sleep(1)
PWM.setMotorModel(-1500,-1500,2000,2000) #Left
2020-03-03 04:39:01 -05:00
print ("The car is turning left")
2019-09-24 21:09:34 -04:00
time.sleep(1)
PWM.setMotorModel(2000,2000,-1500,-1500) #Right
2020-03-03 04:39:01 -05:00
print ("The car is turning right")
2019-09-24 21:09:34 -04:00
time.sleep(1)
PWM.setMotorModel(0,0,0,0) #Stop
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2019-09-24 21:09:34 -04:00
except KeyboardInterrupt:
PWM.setMotorModel(0,0,0,0)
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2019-09-24 21:09:34 -04:00
from Ultrasonic import *
ultrasonic=Ultrasonic()
def test_Ultrasonic():
try:
while True:
data=ultrasonic.get_distance() #Get the value
print ("Obstacle distance is "+str(data)+"CM")
time.sleep(1)
except KeyboardInterrupt:
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2019-09-24 21:09:34 -04:00
from Line_Tracking import *
2020-07-08 22:21:44 -04:00
line=Line_Tracking()
2019-09-24 21:09:34 -04:00
def test_Infrared():
try:
while True:
2020-07-08 22:21:44 -04:00
if GPIO.input(line.IR01)!=True and GPIO.input(line.IR02)==True and GPIO.input(line.IR03)!=True:
2020-03-03 04:39:01 -05:00
print ('Middle')
2020-07-08 22:21:44 -04:00
elif GPIO.input(line.IR01)!=True and GPIO.input(line.IR02)!=True and GPIO.input(line.IR03)==True:
2020-03-03 04:39:01 -05:00
print ('Right')
2020-07-08 22:21:44 -04:00
elif GPIO.input(line.IR01)==True and GPIO.input(line.IR02)!=True and GPIO.input(line.IR03)!=True:
2020-03-03 04:39:01 -05:00
print ('Left')
2019-09-24 21:09:34 -04:00
except KeyboardInterrupt:
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2019-09-24 21:09:34 -04:00
from servo import *
pwm=Servo()
def test_Servo():
try:
while True:
for i in range(50,110,1):
pwm.setServoPwm('0',i)
time.sleep(0.01)
for i in range(110,50,-1):
pwm.setServoPwm('0',i)
time.sleep(0.01)
for i in range(80,150,1):
pwm.setServoPwm('1',i)
time.sleep(0.01)
for i in range(150,80,-1):
pwm.setServoPwm('1',i)
time.sleep(0.01)
except KeyboardInterrupt:
pwm.setServoPwm('0',90)
pwm.setServoPwm('1',90)
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2019-09-24 21:09:34 -04:00
from ADC import *
adc=Adc()
def test_Adc():
try:
while True:
Left_IDR=adc.recvADC(0)
print ("The photoresistor voltage on the left is "+str(Left_IDR)+"V")
Right_IDR=adc.recvADC(1)
print ("The photoresistor voltage on the right is "+str(Right_IDR)+"V")
Power=adc.recvADC(2)
print ("The battery voltage is "+str(Power*3)+"V")
time.sleep(1)
2020-03-03 04:39:01 -05:00
print ('\n')
2019-09-24 21:09:34 -04:00
except KeyboardInterrupt:
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2019-09-24 21:09:34 -04:00
from Buzzer import *
buzzer=Buzzer()
def test_Buzzer():
try:
buzzer.run('1')
time.sleep(1)
2020-03-03 04:39:01 -05:00
print ("1S")
2019-09-24 21:09:34 -04:00
time.sleep(1)
2020-03-03 04:39:01 -05:00
print ("2S")
2019-09-24 21:09:34 -04:00
time.sleep(1)
2020-03-03 04:39:01 -05:00
print ("3S")
2019-09-24 21:09:34 -04:00
buzzer.run('0')
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2019-09-24 21:09:34 -04:00
except KeyboardInterrupt:
buzzer.run('0')
2020-03-03 04:39:01 -05:00
print ("\nEnd of program")
2020-09-01 03:38:54 -04:00
2019-09-24 21:09:34 -04:00
# Main program logic follows:
if __name__ == '__main__':
print ('Program is starting ... ')
import sys
if len(sys.argv)<2:
2020-03-03 04:39:01 -05:00
print ("Parameter error: Please assign the device")
2019-09-24 21:09:34 -04:00
exit()
if sys.argv[1] == 'Led':
test_Led()
elif sys.argv[1] == 'Motor':
test_Motor()
elif sys.argv[1] == 'Ultrasonic':
test_Ultrasonic()
elif sys.argv[1] == 'Infrared':
test_Infrared()
elif sys.argv[1] == 'Servo':
test_Servo()
elif sys.argv[1] == 'ADC':
test_Adc()
elif sys.argv[1] == 'Buzzer':
2020-09-01 03:38:54 -04:00
test_Buzzer()
2019-09-24 21:09:34 -04:00