In this video I show how to use both cores on the Raspberry Pi Pico W. We will explore an example using threading where we will operate 2 LED and a servo.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# ==================================================================== # DISCLAIMER: # This code is provided as-is for educational and experimental # purposes only. The author makes no representations or warranties of # any kind concerning the safety, suitability, or accuracy of this # code. Use at your own risk. The author assumes no liability for any # damages, system failures, security breaches, or network issues # resulting from the use or implementation of this script. # ==================================================================== from machine import Pin import time import _thread import SERVO greenPin=14 redPin=15 servoPin=17 LED="" redLED=Pin(redPin,Pin.OUT) greenLED=Pin(greenPin,Pin.OUT) delOn=.1 delOff=.1 myServo=SERVO.servo(servoPin) running =True def othCore(del1,del2): global LED while True: if LED=="RED": redLED.value(1) time.sleep(del1) redLED.value(0) time.sleep(del2) if LED=="GREEN": greenLED.value(1) time.sleep(del1) greenLED.value(0) time.sleep(del2) _thread.start_new_thread(othCore,(delOn,delOff)) ts=.25 time.sleep(ts) ts=.01 while True: LED="RED" for i in range(0,180,1): myServo.pos(i) time.sleep(ts) LED="GREEN" for i in range(180,0,-1): myServo.pos(i) time.sleep(ts) |