from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf, sys
import utime
push_butt = Pin(28, Pin.IN, Pin.PULL_DOWN) #button PULL_DOWN вытягивание если на GND
zummer_beep = Pin(29, Pin.OUT) #Zumer beep
zummer_beep.value(0)
images = []
led = Pin(25, Pin.OUT) # 14 number in is Output
push_button = Pin(24, Pin.IN) # 13 number pin is input
status_alarm = 0
def init_i2c(scl_pin, sda_pin):
# Initialize I2C device
i2c_dev = I2C(1, scl=Pin(scl_pin), sda=Pin(sda_pin), freq=200000)
i2c_addr = [hex(ii) for ii in i2c_dev.scan()]
if not i2c_addr:
print('No I2C Display Found')
sys.exit()
else:
print("I2C Address : {}".format(i2c_addr[0]))
print("I2C Configuration: {}".format(i2c_dev))
return i2c_dev
def realtime():
current_time = time.localtime()
timestamp = "{:02}:{:02} ___ {:02}/{:02}".format(current_time[3],
current_time[4], current_time[1], current_time[2])
t=str("{}".format(timestamp))
display.text(t, 0, 0)
#print(t)
display.show()
def openpbm():
with open('logoPR128.pbm', 'rb') as f:
f.readline() # number
f.readline() # Creator
f.readline() # Dimensions
data = bytearray(f.read())
fbuf = framebuf.FrameBuffer(data, 128, 64, framebuf.MONO_HLSB)
display.invert(0)
display.contrast(1)
display.blit(fbuf, 0, 0)
# realtime()
display.show()
def openpbmbee():
display.fill(0)
for i in images:
display.blit(i, 0, 0) # расположение картинки на дисплее 128 64 - 25 горизонт 10 - вертикальн
display.show()
#time.sleep(0.001) #задерчка между переходом на следующюю картинку
def beepalarm():
np[0] = (20, 0, 0)
np.write()
for i in range(5):
zummer_beep.toggle()
time.sleep(0.03)
zummer_beep.toggle()
time.sleep(0.2)
time.sleep(0.5)
zummer_beep.value(0)
def senduartalarm():
uart.write("\n\r")
time.sleep(3)
print("send to uart - ATD>1;")
uart.write("ATD>1;")
time.sleep(0.3)
uart.write("\n\r")
time.sleep(6)
uart.write("ATH")
uart.write("\n\r")
if logic_state == True:
print("button on ", push_butt.value())
beepalarm()
print("stat alarm = ",status_alarm)
if status_alarm == 1:
senduartalarm()
def display_logo(oled):
# Display the Raspberry Pi logo on the OLED
buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
oled.fill(0)
oled.blit(fb, 96, 0)
oled.show()
def display_text(oled):
# Display text on the OLED
oled.text("Raspberry Pi", 5, 5)
oled.text("Pico", 5, 15)
oled.show()
def display_anima(oled):
# Display a simple timer animation on the OLED
start_time = utime.ticks_ms()
while True:
elapsed_time = (utime.ticks_diff(utime.ticks_ms(), start_time) // 1000) + 1
# Clear the specific line by drawing a filled black rectangle
oled.fill_rect(5, 40, oled.width - 5, 8, 0)
oled.text("Timer:", 5, 30)
oled.text(str(elapsed_time) + " sec", 7, 40)
oled.show()
utime.sleep_ms(1000)
def main():
i2c_dev = init_i2c(scl_pin=27, sda_pin=26)
oled = SSD1306_I2C(128, 64, i2c_dev)
display_logo(oled)
display_text(oled)
display_anima(oled)
if __name__ == '__main__':
main()