Skip to content

Instantly share code, notes, and snippets.

@ugeugeHigh
Last active March 2, 2022 05:17
Show Gist options
  • Save ugeugeHigh/8d6630ba533da2966585ea2fc0cafea4 to your computer and use it in GitHub Desktop.
Save ugeugeHigh/8d6630ba533da2966585ea2fc0cafea4 to your computer and use it in GitHub Desktop.
import segment
import time
import utime
import machine
import math
sensor_temp = machine.ADC(4)
conversion_factor = 3.3/(65535)
while True:
reading = sensor_temp.read_u16()*conversion_factor
temperature = 27 - (reading - 0.706)/0.001721
temperature = math.ceil(temperature)
print(temperature)
first_digit = temperature % 10
second_digit = temperature // 10
segment.A(first_digit)
segment.C(second_digit)
time.sleep(1)
from machine import Pin
#Cathode common segment pin set up
led1 = Pin(0, Pin.OUT)
led2 = Pin(1,Pin.OUT)
led4 = Pin(2,Pin.OUT)
led6 = Pin(3,Pin.OUT)
led7 = Pin(4,Pin.OUT)
led9 = Pin(5,Pin.OUT)
led10 = Pin(6,Pin.OUT)
#Anode common segment pin set up
led1_ = Pin(7, Pin.OUT)
led2_ = Pin(8,Pin.OUT)
led4_ = Pin(9,Pin.OUT)
led6_ = Pin(10,Pin.OUT)
led7_ = Pin(11,Pin.OUT)
led9_ = Pin(12,Pin.OUT)
led10_ = Pin(13,Pin.OUT)
def Coff():
led1.value(0)
led2.value(0)
led4.value(0)
led6.value(0)
led7.value(0)
led9.value(0)
led10.value(0)
def C0():
led1.value(1)
led2.value(1)
led4.value(1)
led6.value(1)
led7.value(1)
led9.value(1)
led10.value(0)
def C1():
led1.value(0)
led2.value(0)
led4.value(1)
led6.value(1)
led7.value(0)
led9.value(0)
led10.value(0)
def C2():
led1.value(1)
led2.value(1)
led4.value(0)
led6.value(1)
led7.value(1)
led9.value(0)
led10.value(1)
def C3():
led1.value(0)
led2.value(1)
led4.value(1)
led6.value(1)
led7.value(1)
led9.value(0)
led10.value(1)
def C4():
led1.value(0)
led2.value(0)
led4.value(1)
led6.value(1)
led7.value(0)
led9.value(1)
led10.value(1)
def C5():
led1.value(0)
led2.value(1)
led4.value(1)
led6.value(0)
led7.value(1)
led9.value(1)
led10.value(1)
def C6():
led1.value(1)
led2.value(1)
led4.value(1)
led6.value(0)
led7.value(1)
led9.value(1)
led10.value(1)
def C7():
led1.value(0)
led2.value(0)
led4.value(1)
led6.value(1)
led7.value(1)
led9.value(1)
led10.value(0)
def C8():
led1.value(1)
led2.value(1)
led4.value(1)
led6.value(1)
led7.value(1)
led9.value(1)
led10.value(1)
def C9():
led1.value(0)
led2.value(0)
led4.value(1)
led6.value(1)
led7.value(1)
led9.value(1)
led10.value(1)
def Aoff():
led1_.value(1)
led2_.value(1)
led4_.value(1)
led6_.value(1)
led7_.value(1)
led9_.value(1)
led10_.value(1)
def A0():
led1_.value(0)
led2_.value(0)
led4_.value(0)
led6_.value(0)
led7_.value(0)
led9_.value(0)
led10_.value(1)
def A1():
led1_.value(1)
led2_.value(1)
led4_.value(0)
led6_.value(0)
led7_.value(1)
led9_.value(1)
led10_.value(1)
def A2():
led1_.value(0)
led2_.value(0)
led4_.value(1)
led6_.value(0)
led7_.value(0)
led9_.value(1)
led10_.value(0)
def A3():
led1_.value(1)
led2_.value(0)
led4_.value(0)
led6_.value(0)
led7_.value(0)
led9_.value(1)
led10_.value(0)
def A4():
led1_.value(1)
led2_.value(1)
led4_.value(0)
led6_.value(0)
led7_.value(1)
led9_.value(0)
led10_.value(0)
def A5():
led1_.value(1)
led2_.value(0)
led4_.value(0)
led6_.value(1)
led7_.value(0)
led9_.value(0)
led10_.value(0)
def A6():
led1_.value(0)
led2_.value(0)
led4_.value(0)
led6_.value(1)
led7_.value(0)
led9_.value(0)
led10_.value(0)
def A7():
led1_.value(1)
led2_.value(1)
led4_.value(0)
led6_.value(0)
led7_.value(0)
led9_.value(0)
led10_.value(1)
def A8():
led1_.value(0)
led2_.value(0)
led4_.value(0)
led6_.value(0)
led7_.value(0)
led9_.value(0)
led10_.value(0)
def A9():
led1_.value(1)
led2_.value(1)
led4_.value(0)
led6_.value(0)
led7_.value(0)
led9_.value(0)
led10_.value(0)
def C(i):
if i == 0:
C0()
elif i == 1:
C1()
elif i == 2:
C2()
elif i == 3:
C3()
elif i == 4:
C4()
elif i == 5:
C5()
elif i == 6:
C6()
elif i == 7:
C7()
elif i == 8:
C8()
elif i == 9:
C9()
def A(i):
if i == 0:
A0()
elif i == 1:
A1()
elif i == 2:
A2()
elif i == 3:
A3()
elif i == 4:
A4()
elif i == 5:
A5()
elif i == 6:
A6()
elif i == 7:
A7()
elif i == 8:
A8()
elif i == 9:
A9()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment