EasyManua.ls Logo

ADEEPT PiCar-Pro - Page 69

ADEEPT PiCar-Pro
178 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
66
2. import time
2. The switchSetup function sets the GPIO pin numbers of the Raspberry Pi
corresponding to the interface to 5, 6, and 13, here we use BCM coding.
1. def switchSetup():
2. GPIO.setwarnings(False)
3. GPIO.setmode(GPIO.BCM)
4. GPIO.setup(5, GPIO.OUT)
5. GPIO.setup(6, GPIO.OUT)
6. GPIO.setup(13, GPIO.OUT)
3. The switch function sets the high and low levels of the interface. Port
represents ports 1-3. When the status is 0, the corresponding interface light is off, and
when the status is 1, the corresponding interface light is on.
1. def switch(port, status):
2. if port == 1:
3. if status == 1:
4. GPIO.output(5, GPIO.HIGH)
5. elif status == 0:
6. GPIO.output(5,GPIO.LOW)
7. else:
8. pass
9. elif port == 2:
10. if status == 1:
11. GPIO.output(6, GPIO.HIGH)
12. elif status == 0:
13. GPIO.output(6,GPIO.LOW)
14. else:
15. pass
16. elif port == 3:
17. if status == 1:
18. GPIO.output(13, GPIO.HIGH)
19. elif status == 0:
20. GPIO.output(13,GPIO.LOW)
21. else:
22. pass
23. else:
24. print('Wrong Command: Example--switch(3, 1)->to switch on port3')
4. The set_all_switch_off function sets the level of all interfaces to low level, that
is, turns off the lights of all interfaces.

Related product manuals