Trim trailing whitespace from example Micropython code
rodzic
712964b1d9
commit
609ab9c79f
|
@ -6,9 +6,9 @@ conversion_factor = 3.3 / (65535)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
reading = sensor_temp.read_u16() * conversion_factor
|
reading = sensor_temp.read_u16() * conversion_factor
|
||||||
|
|
||||||
# The temperature sensor measures the Vbe voltage of a biased bipolar diode, connected to the fifth ADC channel
|
# The temperature sensor measures the Vbe voltage of a biased bipolar diode, connected to the fifth ADC channel
|
||||||
# Typically, Vbe = 0.706V at 27 degrees C, with a slope of -1.721mV (0.001721) per degree.
|
# Typically, Vbe = 0.706V at 27 degrees C, with a slope of -1.721mV (0.001721) per degree.
|
||||||
temperature = 27 - (reading - 0.706)/0.001721
|
temperature = 27 - (reading - 0.706)/0.001721
|
||||||
print(temperature)
|
print(temperature)
|
||||||
utime.sleep(2)
|
utime.sleep(2)
|
||||||
|
|
|
@ -221,7 +221,7 @@ class BLETemperatureCentral:
|
||||||
def sleep_ms_flash_led(self, flash_count, delay_ms):
|
def sleep_ms_flash_led(self, flash_count, delay_ms):
|
||||||
self._led.off()
|
self._led.off()
|
||||||
while(delay_ms > 0):
|
while(delay_ms > 0):
|
||||||
for i in range(flash_count):
|
for i in range(flash_count):
|
||||||
self._led.on()
|
self._led.on()
|
||||||
time.sleep_ms(100)
|
time.sleep_ms(100)
|
||||||
self._led.off()
|
self._led.off()
|
||||||
|
@ -267,4 +267,4 @@ if __name__ == "__main__":
|
||||||
central = BLETemperatureCentral(ble)
|
central = BLETemperatureCentral(ble)
|
||||||
while(True):
|
while(True):
|
||||||
demo(ble, central)
|
demo(ble, central)
|
||||||
sleep_ms_flash_led(central, 1, 10000)
|
sleep_ms_flash_led(central, 1, 10000)
|
||||||
|
|
|
@ -86,11 +86,11 @@ class BLETemperature:
|
||||||
def _get_temp(self):
|
def _get_temp(self):
|
||||||
conversion_factor = 3.3 / (65535)
|
conversion_factor = 3.3 / (65535)
|
||||||
reading = self._sensor_temp.read_u16() * conversion_factor
|
reading = self._sensor_temp.read_u16() * conversion_factor
|
||||||
|
|
||||||
# The temperature sensor measures the Vbe voltage of a biased bipolar diode, connected to the fifth ADC channel
|
# The temperature sensor measures the Vbe voltage of a biased bipolar diode, connected to the fifth ADC channel
|
||||||
# Typically, Vbe = 0.706V at 27 degrees C, with a slope of -1.721mV (0.001721) per degree.
|
# Typically, Vbe = 0.706V at 27 degrees C, with a slope of -1.721mV (0.001721) per degree.
|
||||||
return 27 - (reading - 0.706) / 0.001721
|
return 27 - (reading - 0.706) / 0.001721
|
||||||
|
|
||||||
def demo():
|
def demo():
|
||||||
ble = bluetooth.BLE()
|
ble = bluetooth.BLE()
|
||||||
temp = BLETemperature(ble)
|
temp = BLETemperature(ble)
|
||||||
|
@ -104,4 +104,4 @@ def demo():
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
demo()
|
demo()
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
# Display Image & text on I2C driven SH1106 OLED display
|
# Display Image & text on I2C driven SH1106 OLED display
|
||||||
from machine import I2C, ADC
|
from machine import I2C, ADC
|
||||||
from sh1106 import SH1106_I2C
|
from sh1106 import SH1106_I2C
|
||||||
import framebuf
|
import framebuf
|
||||||
|
|
||||||
|
|
||||||
WIDTH = 128 # oled display width
|
WIDTH = 128 # oled display width
|
||||||
HEIGHT = 128 # oled display height
|
HEIGHT = 128 # oled display height
|
||||||
|
|
||||||
|
@ -31,4 +30,4 @@ oled.text("Raspberry Pi",5,5)
|
||||||
oled.text("Pico",5,15)
|
oled.text("Pico",5,15)
|
||||||
|
|
||||||
# Finally update the oled display so the image & text is displayed
|
# Finally update the oled display so the image & text is displayed
|
||||||
oled.show()
|
oled.show()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Display Image & text on I2C driven ssd1306 OLED display
|
# Display Image & text on I2C driven ssd1306 OLED display
|
||||||
from machine import Pin, I2C
|
from machine import Pin, I2C
|
||||||
from sh1106 import SH1106_I2C
|
from sh1106 import SH1106_I2C
|
||||||
import framebuf
|
import framebuf
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Display Image & text on I2C driven ssd1306 OLED display
|
# Display Image & text on I2C driven ssd1306 OLED display
|
||||||
from machine import Pin, I2C
|
from machine import Pin, I2C
|
||||||
from ssd1306 import SSD1306_I2C
|
from ssd1306 import SSD1306_I2C
|
||||||
import framebuf
|
import framebuf
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Display Image & text on I2C driven ssd1306 OLED display
|
# Display Image & text on I2C driven ssd1306 OLED display
|
||||||
from machine import Pin, I2C
|
from machine import Pin, I2C
|
||||||
from ssd1306 import SSD1306_I2C
|
from ssd1306 import SSD1306_I2C
|
||||||
import framebuf
|
import framebuf
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from machine import Pin, I2C
|
from machine import Pin, I2C
|
||||||
|
|
||||||
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=100000)
|
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=100000)
|
||||||
i2c.scan()
|
i2c.scan()
|
||||||
i2c.writeto(76, b'123')
|
i2c.writeto(76, b'123')
|
||||||
i2c.readfrom(76, 4)
|
i2c.readfrom(76, 4)
|
||||||
|
|
|
@ -57,7 +57,7 @@ def color_chase(color, wait):
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
pixels_show()
|
pixels_show()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
def wheel(pos):
|
def wheel(pos):
|
||||||
# Input a value 0 to 255 to get a color value.
|
# Input a value 0 to 255 to get a color value.
|
||||||
# The colours are a transition r - g - b - back to r.
|
# The colours are a transition r - g - b - back to r.
|
||||||
|
@ -70,8 +70,7 @@ def wheel(pos):
|
||||||
return (0, 255 - pos * 3, pos * 3)
|
return (0, 255 - pos * 3, pos * 3)
|
||||||
pos -= 170
|
pos -= 170
|
||||||
return (pos * 3, 0, 255 - pos * 3)
|
return (pos * 3, 0, 255 - pos * 3)
|
||||||
|
|
||||||
|
|
||||||
def rainbow_cycle(wait):
|
def rainbow_cycle(wait):
|
||||||
for j in range(255):
|
for j in range(255):
|
||||||
for i in range(NUM_LEDS):
|
for i in range(NUM_LEDS):
|
||||||
|
@ -91,14 +90,14 @@ WHITE = (255, 255, 255)
|
||||||
COLORS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE)
|
COLORS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE)
|
||||||
|
|
||||||
print("fills")
|
print("fills")
|
||||||
for color in COLORS:
|
for color in COLORS:
|
||||||
pixels_fill(color)
|
pixels_fill(color)
|
||||||
pixels_show()
|
pixels_show()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
print("chases")
|
print("chases")
|
||||||
for color in COLORS:
|
for color in COLORS:
|
||||||
color_chase(color, 0.01)
|
color_chase(color, 0.01)
|
||||||
|
|
||||||
print("rainbow")
|
print("rainbow")
|
||||||
rainbow_cycle(0)
|
rainbow_cycle(0)
|
||||||
|
|
Ładowanie…
Reference in New Issue