[{"data":1,"prerenderedAt":85},["ShallowReactive",2],{"example-page-uno-traffic":3},{"id":4,"info":5,"parts":6,"wired":17,"refs":18,"nets":19,"moreNets":79,"code":80},"uno-traffic","Three LEDs on D10 (red), D9 (yellow) and D8 (green) run the traffic light phases. Press SW1 (on D2, with the internal pull-up): green ends early and the light turns red for the pedestrians. The sketch uses millis() instead of delay(), so it always reads the button. The Uno is powered over USB; the serial console shows each phase with its time.",[7,10,12,15],[8,9],"led",3,[11,9],"resistor",[13,14],"arduino_uno",1,[16,14],"button",false,{"A1":13,"D1":8,"D2":8,"D3":8,"SW1":16,"R3":11,"R1":11,"R2":11},[20,36,42,49,55,62,67,74],{"name":21,"pins":22},"0",[23,26,29,31,33],[24,25],"A1","GND",[27,28],"D1","K",[30,28],"D2",[32,28],"D3",[34,35],"SW1","2",{"name":37,"pins":38},"BTN",[39,40],[24,30],[34,41],"1",{"name":43,"pins":44},"GRN",[45,47],[24,46],"D8",[48,41],"R3",{"name":50,"pins":51},"GRN_A",[52,54],[32,53],"A",[48,35],{"name":56,"pins":57},"RED",[58,60],[24,59],"~D10\u002FSS",[61,41],"R1",{"name":63,"pins":64},"RED_A",[65,66],[27,53],[61,35],{"name":68,"pins":69},"YEL",[70,72],[24,71],"~D9",[73,41],"R2",{"name":75,"pins":76},"YEL_A",[77,78],[30,53],[73,35],0,{"file":81,"lang":82,"text":83,"lines":84,"more":17},"sketch.ino","cpp","\u002F\u002F Traffic light: red D10, yellow D9, green D8. The button on D2 (to GND) asks for red:\n\u002F\u002F green ends early. No delay() in the loop, so the button is always read (millis state machine).\nconst int RED = 10, YELLOW = 9, GREEN = 8, BUTTON = 2;\nenum Phase { RED_ON, RED_YELLOW, GREEN_ON, YELLOW_ON };\nconst unsigned long DURATION[] = { 4000, 1000, 5000, 1500 };   \u002F\u002F ms per phase\nPhase phase = RED_ON;\nunsigned long since = 0;\nbool request = false;\n\nvoid show() {\n  digitalWrite(RED, phase == RED_ON || phase == RED_YELLOW);\n  digitalWrite(YELLOW, phase == RED_YELLOW || phase == YELLOW_ON);\n  digitalWrite(GREEN, phase == GREEN_ON);\n  const char *names[] = { \"red\", \"red+yellow\", \"green\", \"yellow\" };\n  Serial.print(millis()); Serial.print(F(\" ms: \")); Serial.println(names[phase]);\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(RED, OUTPUT); pinMode(YELLOW, OUTPUT); pinMode(GREEN, OUTPUT);\n  pinMode(BUTTON, INPUT_PULLUP);\n  show();\n}\n\nvoid loop() {\n  if (digitalRead(BUTTON) == LOW && !request) { request = true; Serial.println(F(\"button: pedestrian waiting\")); }\n  unsigned long d = DURATION[phase];\n  if (phase == GREEN_ON && request) d = 1000;               \u002F\u002F shorten green\n  if (millis() - since >= d) {\n    phase = (Phase)((phase + 1) % 4);\n    since = millis();\n    if (phase == RED_ON) request = false;\n    show();\n  }\n}",35,1796304409785]