This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from machine import Pin | |
| from neopixel import NeoPixel | |
| from time import sleep | |
| RED =(255, 0, 0) | |
| GREEN =(0, 255, 0) | |
| BLUE =(0, 0, 255) | |
| WHITE =(255, 255, 255) | |
| pixels = NeoPixel(Pin(22, Pin.OUT), 30) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from machine import Pin, PWM | |
| from time import sleep | |
| servo = PWM(Pin(18), freq=50, duty=0) | |
| def set_angle(angle): | |
| global servo | |
| servo.duty(int(((angle + 90) * 2 / 180 + 0.5) / 20 * 1023)) | |
| set_angle(-90) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from machine import SoftI2C, Pin | |
| from ssd1306 import SSD1306_I2C | |
| from time import sleep | |
| from mpu6050 import Accel | |
| i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
| display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
| i2c2 = SoftI2C(sda=Pin(22), scl=Pin(32)) # SDA=Y11, SCL=Y12 | |
| accelerometer = Accel(i2c2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from time import sleep_us, ticks_us | |
| class HCSR04(): | |
| def __init__(self,trig,echo): | |
| self.trig=trig | |
| self.echo=echo | |
| def getDistance(self): | |
| distance=0 | |
| self.trig.value(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BMP280_I2C_ADDR = const(0x76) | |
| class BMP280(): | |
| def __init__(self, i2c): | |
| self.i2c = i2c | |
| self.dig_T1 = self.get2Reg(0x88) | |
| self.dig_T2 = self.short(self.get2Reg(0x8A)) | |
| self.dig_T3 = self.short(self.get2Reg(0x8C)) | |
| self.dig_P1 = self.get2Reg(0x8E) | |
| self.dig_P2 = self.short(self.get2Reg(0x90)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from machine import Pin, SoftI2C, ADC | |
| from ssd1306 import SSD1306_I2C | |
| from time import sleep | |
| i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
| display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
| waterLevel = ADC(Pin(32)) | |
| waterLevel.atten(ADC.ATTN_11DB) # 150mV - 2450mV |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from machine import Pin, SoftI2C, ADC | |
| from ssd1306 import SSD1306_I2C | |
| from time import sleep | |
| i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
| display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
| soil = ADC(Pin(32)) | |
| soil.atten(ADC.ATTN_11DB) # 150mV - 2450mV |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from machine import Pin, SoftI2C, ADC | |
| from ssd1306 import SSD1306_I2C | |
| from time import sleep | |
| i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
| display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
| light = ADC(Pin(32)) | |
| light.atten(ADC.ATTN_11DB) # 150mV - 2450mV |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from machine import SoftI2C, Pin | |
| from ssd1306 import SSD1306_I2C | |
| from time import sleep | |
| i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
| display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
| pir = Pin(22, Pin.IN, Pin.PULL_UP) | |
| display.fill(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from machine import Pin, SoftI2C | |
| from ssd1306 import SSD1306_I2C | |
| from dht import DHT11 | |
| from time import sleep | |
| i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
| display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
| dt = DHT11(Pin(27)) | |
| sleep(2) |