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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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/ import time from machine import Pin, SoftI2C,ADC import ssd1306 from hcsr04 import HCSR04 from time import sleep VP_PIN = 25 # VP pin VB_PIN = 26 # VB pin s = ADC(Pin(25)) s.atten(ADC.ATTN_11DB) #Full range: 3.3v # ESP32 sensor = HCSR04(trigger_pin=0, echo_pin=4, echo_timeout_us=10000) led1 = Pin(14,Pin.OUT) # red led led = Pin(12,Pin.OUT) # h reen led buz = Pin(23,Pin.OUT) # buz button = Pin(35, Pin.IN, Pin.PULL_UP) # button connected to pin 4 button1 = Pin(39, Pin.IN, Pin.PULL_UP) # button connected to pin 4 # ESP32 Pin assignment i2c = SoftI2C(scl=Pin(22), sda=Pin(21)) # ESP8266 Pin assignment #i2c = SoftI2C(scl=Pin(5), sda=Pin(4)) oled_width = 128 oled_height = 64 oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c) print("Hello, Robotics blocks - led on off v2 ") oled.text('Hello, World 1! v2', 0, 0) oled.show() while True: if button1.value() == 0 : print("button on") sleep(1) if button1.value() == 1 : print("button off") sleep(1) val = s.read() print("Voltage:", val) time.sleep_ms(1000) oled.fill(0) #oled.show() distance = sensor.distance_mm() print('Distance:', distance, 'mm') oled.text("Distance (mm)", 0, 15) oled.text(str(distance), 0, 35) oled.show() if distance <=100 : led1.value(1) led.value(0) buz.value(1) else: led.value(1) led1.value(0) buz.value(0) #if not button.value(): # buz.value(0) #else: # buz.value(1) sleep(0.25) |