חוג רובוטיקה – ספריית דוגמאות מיקרו פייתון – רובוטיקס בלוקס
הדלקת לד
https://wokwi.com/projects/354783764172911617
1 2 3 4 5 6 7 8 9 10 11 |
import time from machine import Pin print("Hello, ESP32!") led = Pin(2,Pin.OUT) while True: led.value(1) time.sleep(0.5) led.value(0) time.sleep(0.5) |
חוג רובוטיקה – לימוד מיקרופייתון – רובוטיקס בלוקס
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import time import machine from machine import Pin print("Hello, ESP32!") led = Pin(2,Pin.OUT) button = machine.Pin(25, machine.Pin.IN, machine.Pin.PULL_UP) # if button pressed = 0 , if button not pressed 0 while True: print("Button state", button.value()) time.sleep(0.1) if button.value() == 0 : led.value(1) time.sleep(0.5) else : led.value(0) time.sleep(0.5) |
הפעלת באזר
https://wokwi.com/projects/354783186330970113
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# www.robotronix.co.il robotics blocks # חוג רובוטיקה # https://robotronix.co.il/%d7%a8%d7%95%d7%91%d7%95%d7%98%d7%a8%d7%95%d7%a0%d7%99%d7%a7%d7%a1-%d7%9b%d7%9c%d7%9c%d7%99/%d7%97%d7%95%d7%92-%d7%a8%d7%95%d7%91%d7%95%d7%98%d7%99%d7%a7%d7%94-%d7%a1%d7%a4%d7%a8%d7%99%d7%99%d7%aa-%d7%93%d7%95%d7%92%d7%9e%d7%90%d7%95%d7%aa-%d7%9e%d7%99%d7%a7%d7%a8%d7%95-%d7%a4%d7%99/ from machine import Pin, PWM import time buzzer = PWM(Pin(2), freq=440, duty=512) def SoundBuz(freq, sleep): buzzer.freq(freq) buzzer.duty(512) time.sleep(sleep) while True: SoundBuz(440, 0.5) SoundBuz(880, 0.5) |
חיישן מרחק
1 2 3 4 5 6 7 8 9 |
from hcsr04 import HCSR04 import time sensor = HCSR04(trigger_pin=12, echo_pin=14, echo_timeout_us=1000000) while True: distance = sensor.distance_cm() print(distance) time.sleep(1) |
https://wokwi.com/projects/354166013666030593
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 56 57 58 59 60 61 62 63 |
from machine import Pin, I2C, ADC import time from ssd1306 import SSD1306_I2C from dht import DHT22 ambiente=DHT22(Pin(15)) sensor = ADC(Pin(34)) ancho = 128 alto = 64 i2c = I2C(0, scl=Pin(22), sda=Pin(23)) oled = SSD1306_I2C(ancho, alto, i2c) # print(i2c.scan()) def saludo(): oled.text("*"*16,0,0) oled.text("Hola Mundo",24,10) oled.text("Bienvenido", 24, 20) oled.text("Python - Devnet", 0, 30) oled.text("*"*16, 0, 40) oled.show() time.sleep(2) def imprimir_pote(): val = int((sensor.read_u16())/500) oled.fill_rect(1,15,val,25,1) oled.show() oled.fill_rect(1,15,val,25,0) time.sleep(0.25) def grafica_sensor(): global acum acum+=1 val = int((sensor.read_u16())/2200) oled.pixel(acum,val+24,1) print (val) oled.show() time.sleep(0.02) if acum==128: acum=0 oled.fill(0) oled.show() saludo() oled.fill(1) oled.show() time.sleep(1) oled.fill(0) oled.show() acum=0 while True: ambiente.measure() temperatura=ambiente.temperature() humedad=ambiente.humidity() print (f"T:{temperatura}\t H:{humedad}") oled.text(f" T:{temperatura} ",0,0,1) oled.text(f" H:{humedad} ",0,8,1) oled.show() time.sleep(0.03) #oled.fill(0) #imprimir_pote() grafica_sensor() |
סרבו
https://wokwi.com/projects/354167148568212481
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 |
# Micropython on ESP32 from machine import Pin,PWM import utime # pwm pwm = PWM(Pin(15), freq=50, duty=0) def Servo(servo, angle): # angle / 180( * 2(0°-180°) + 0.5()/ 20ms * 1023 pwm.duty(int(((angle)/180 *2 + 0.5) / 20 * 1023)) # Servo(pwm, 0) utime.sleep(1) Servo(pwm, 180) utime.sleep(1) Servo(pwm, 0) utime.sleep(3) print("Start steps :") # now lets add loop for i in range (0 , 181, 30) : # 0 - start , 181 - to , 30 = steps Servo(pwm, i) utime.sleep(1) print("Servo Angle : ",i) |
שימוש ב HTTP WIFI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# MicroPython HTTPS example for Wokwi.com import network import urequests import time # Connect to WiFi print("Connecting to WiFi", end="") sta_if = network.WLAN(network.STA_IF) sta_if.active(True) sta_if.connect('Wokwi-GUEST', '') while not sta_if.isconnected(): print(".", end="") time.sleep(0.25) print("Connected!") # Send HTTPS request print("Sending HTTPS request... ", end="") response = urequests.get("https://api.dictionaryapi.dev/api/v2/entries/en/success") print(response.text) |
דרייבר מנוע
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 |
from machine import Pin import time # Define the pins for the motor enable_pin = Pin(12, Pin.OUT) motor_pin1 = Pin(14, Pin.OUT) motor_pin2 = Pin(27, Pin.OUT) # Function to drive the motor def drive(direction, speed): # Set the direction of the motor if direction == "forward": motor_pin1.value(1) motor_pin2.value(0) elif direction == "backward": motor_pin1.value(0) motor_pin2.value(1) else: print("Invalid direction") return # Set the speed of the motor enable_pin.value(speed) # Drive the motor forward at 50% speed drive("forward", 1) time.sleep(2) # Drive the motor backward at 75% speed drive("backward", 1) time.sleep(2) # Stop the motor drive("stop", 0) |
פייתון היא שפת תכנות גבוהה מתוכנתת, המשמשת ברחבי התחומים כגון פיתוח אינטרנט, מדע מחקרי, ניתוח נתונים, הנדסת חישה מלאכותית ועוד. היא מאוכזבת על הנקיון ונוחות הכתיבה, הקריאה וההתאמה לכל הכוונות השונות. היא ננספת להשתמש כשפת "סקריפטים" עבור פיתוח אתרי אינטרנט ועוד.
מיקרופייתון הוא מערכת פיתוח מחזורית שמשתמשת בשפת פייתון כשפת התכנות העיקרית. המערכת מאפשרת לפיתוח מהיר ונוח של מערכות תכנה מסוג חכם ומערכות למידה עצמאית. זה ננסך להשתמש במערכת זו כדי לפתח את האלגוריתמים והמערכות המנסה להשתמש בנתונים וביכולות חכמה על מנת לפתח תכניות ומערכות עם יכולת לנסות ולהשתגע עצמאית.
קישורים :
http://ms2.ctjh.ntpc.edu.tw/~luti/110wokwi-microPython-2.htm