If you long for the old models that were opened with a rotary switch, which was turned left and right until the correct numerical combination was achieved, you can always ride this circuit.
When the word “turn” appears on the TMS1637, turn the KY-04 rotary encoder clockwise to the first number in the combination. Wait 2 seconds until the “Good” message appears. Wait until our number comes up again, and turn left until the next combination. Repeat the process, now to the right, then to the left.
If you have entered the 4 numbers correctly (the number can be easily expanded), the message “Open” will appear and the relay will open.
When we have stolen all the jewels , we press the central button of the KY-04, with which we will be able to close the relay.
' Opening codes dim safeKey(3) = 26, -11, 40, -18 key = 0 : code = 0 : pos = 0 ' Messages turn$ = "turn" good$ = "good" open$ = str$(0) + "pen" ' Setup ' door lock -> GPIO2 (D4) ' TM1637: CLK -> GPIO1 (TX), DIO -> GPIO3 (RX) ' KY-04: CLK -> GPIO5 (D1), DT -> GPIO4 (D2), SW -> GPIO0 (D3) pin.mode 0, input, pullup pin.mode 1, output pin.mode 2, output pin.mode 3, output pin.mode 4, input pin.mode 5, input DT = 4 CLK = 5 SW = 0 lock = 2 lastCLK = pin(CLK) tm1637.setup 3, 1 ' Don't forget the 10k pullup resistors tm1637.print turn$ WHILE 1 if pin(CLK) <> lastCLK then lastCLK = pin(CLK) if pin(CLK) <> pin(DT) then pos = pos + 0.5 else pos = pos - 0.5 code = cInt(pos) if pos > 50 then pos = 50 if pos < -50 then pos = -50 tm1637.print str$(code, "%4.0f") end if if code = safeKey(key) then pause 2000 if code = safeKey(key) then tm1637.print good$ pause 2000 tm1637.print str$(code, "%4.0f") key = key +1 end if end if if key = 4 then tm1637.print open$ pin(lock) = 1 do loop until pin(SW) = 0 pin(lock) = 0 reboot end if WEND
But that is already to improve the school grade.