[{"data":1,"prerenderedAt":78},["ShallowReactive",2],{"example-page-uno-counter":3},{"id":4,"info":5,"parts":6,"wired":16,"refs":17,"nets":18,"moreNets":72,"code":73},"uno-counter","Operate the KY-040 rotary encoder in the schematic: clicking the left half turns it one detent left, the right half one detent right, and the middle presses the button (counter to 0). The sketch decodes the quadrature signals on CLK\u002FDT, and the four-digit TM1637 display shows the value (TM1637Display library). The logic analyzer shows CLK and DT out of phase.",[7,10,12,14],[8,9],"arduino_uno",1,[11,9],"encoder_ky040",[13,9],"tm1637",[15,9],"vdc",false,{"A1":8,"DS1":13,"SW1":11,"V1":15},[19,32,41,47,53,59,65],{"name":20,"pins":21},"0",[22,25,27,29],[23,24],"A1","GND",[26,24],"DS1",[28,24],"SW1",[30,31],"V1","−",{"name":33,"pins":34},"5V",[35,36,38,40],[23,33],[26,37],"VCC",[28,39],"+",[30,39],{"name":42,"pins":43},"CLK",[44,46],[23,45],"D2",[28,42],{"name":48,"pins":49},"DT",[50,52],[23,51],"~D3",[28,48],{"name":54,"pins":55},"SW",[56,58],[23,57],"D4",[28,54],{"name":60,"pins":61},"TCLK",[62,64],[23,63],"~D5",[26,42],{"name":66,"pins":67},"TDIO",[68,70],[23,69],"~D6",[26,71],"DIO",0,{"file":74,"lang":75,"text":76,"lines":77,"more":16},"sketch.ino","cpp","\u002F\u002F Rotary encoder KY-040 (CLK D2, DT D3, SW D4) sets a number, the TM1637 display (CLK D5, DIO D6)\n\u002F\u002F shows it; pressing resets it to 0\n#include \u003CTM1637Display.h>\nconst int CLK = 2, DT = 3, SW = 4;\nTM1637Display display(5, 6);\nint value = 0, lastClk;\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(CLK, INPUT); pinMode(DT, INPUT); pinMode(SW, INPUT_PULLUP);\n  display.setBrightness(5);\n  display.showNumberDec(value);\n  lastClk = digitalRead(CLK);\n}\n\nvoid loop() {\n  int clk = digitalRead(CLK);\n  if (clk != lastClk && clk == LOW) {                 \u002F\u002F one detent: CLK falls, DT gives the direction\n    value += digitalRead(DT) != clk ? 1 : -1;\n    value = constrain(value, -999, 9999);\n    display.showNumberDec(value);\n    Serial.println(value);\n  }\n  lastClk = clk;\n  if (digitalRead(SW) == LOW) { value = 0; display.showNumberDec(value); Serial.println(F(\"Reset\")); delay(250); }\n}",26,1796304400897]