{"about":"Argynix Lab's examples, each a project in the form https://lab.argynix.com/ai describes.","examples":[{"id":"blink","name":"Blink","summary":"An LED on pin 13, on and off every half second.","open":"https://lab.argynix.com/bench?example=blink&run=1&view=3d","project":{"name":"Blink","ide":"arduino","board":"arduino-uno","code":"// Blink: the LED on pin 13 turns on and off every half second,\n// and the board says hello on the serial port each time.\n\nvoid setup() {\n  pinMode(13, OUTPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  digitalWrite(13, HIGH);\n  Serial.println(\"Hello from Argynix Lab\");\n  delay(500);\n  digitalWrite(13, LOW);\n  delay(500);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":236,"y":92},{"id":"led1","type":"led","attrs":{"color":"red"},"x":316,"y":58}],"wires":[["board:13","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"]]}},{"id":"button","name":"Button and LED","summary":"Hold the button and the LED lights; the serial port says so.","open":"https://lab.argynix.com/bench?example=button&run=1&view=3d","project":{"name":"Button and LED","ide":"arduino","board":"arduino-uno","code":"// Hold the button: the LED lights. The button joins pin 2 to GND, so with\n// INPUT_PULLUP the pin reads LOW while it is pressed.\n\nconst int BUTTON = 2;\nconst int LED = 13;\n\nvoid setup() {\n  pinMode(BUTTON, INPUT_PULLUP);\n  pinMode(LED, OUTPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  static bool was = false;\n  bool pressed = digitalRead(BUTTON) == LOW;\n  digitalWrite(LED, pressed ? HIGH : LOW);\n  if (pressed != was) {\n    Serial.println(pressed ? \"Pressed\" : \"Released\");\n    was = pressed;\n  }\n  delay(5);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":214,"y":92},{"id":"led1","type":"led","attrs":{"color":"green"},"x":292,"y":58},{"id":"b1","type":"pushbutton","attrs":{"color":"blue"},"x":380,"y":96}],"wires":[["board:13","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"],["board:2","b1:1.l"],["b1:2.l","board:GND.1"]]}},{"id":"fade","name":"Fade (PWM)","summary":"analogWrite() on pin 9: the LED breathes.","open":"https://lab.argynix.com/bench?example=fade&run=1&view=3d","project":{"name":"Fade (PWM)","ide":"arduino","board":"arduino-uno","code":"// analogWrite() on a PWM pin: the LED breathes in and out.\n\nconst int LED = 9;\n\nvoid setup() {\n  pinMode(LED, OUTPUT);\n}\n\nvoid loop() {\n  for (int v = 0; v <= 255; v += 5) {\n    analogWrite(LED, v);\n    delay(20);\n  }\n  for (int v = 255; v >= 0; v -= 5) {\n    analogWrite(LED, v);\n    delay(20);\n  }\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":250,"y":92},{"id":"led1","type":"led","attrs":{"color":"blue"},"x":330,"y":58}],"wires":[["board:9","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"]]}},{"id":"knob","name":"Knob to Plotter","summary":"Turn the potentiometer; analogRead() follows it. Open the Plotter.","open":"https://lab.argynix.com/bench?example=knob&run=1&view=3d","project":{"name":"Knob to Plotter","ide":"arduino","board":"arduino-uno","code":"// Turn the knob: analogRead() follows it and the LED's brightness too.\n// Open the Plotter tab to watch it drawn.\n\nconst int KNOB = A0;\nconst int LED = 9;\n\nvoid setup() {\n  pinMode(LED, OUTPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  int raw = analogRead(KNOB);\n  analogWrite(LED, raw / 4);\n  Serial.print(\"knob:\");\n  Serial.println(raw);\n  delay(50);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"p1","type":"potentiometer","x":290,"y":470},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":250,"y":92},{"id":"led1","type":"led","attrs":{"color":"yellow"},"x":330,"y":58}],"wires":[["board:9","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"],["p1:GND","board:GND.3"],["p1:VCC","board:5V"],["p1:SIG","board:A0"]]}},{"id":"melody","name":"Melody","summary":"tone() on pin 8 plays a scale. Turn the sound on to hear it.","open":"https://lab.argynix.com/bench?example=melody&run=1&view=3d","project":{"name":"Melody","ide":"arduino","board":"arduino-uno","code":"// tone() on pin 8: a scale, then a rest. Turn the sound on to hear it.\n\nconst int BUZZER = 8;\nconst int notes[] = { 262, 294, 330, 349, 392, 440, 494, 523 };\n\nvoid setup() {\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  for (int i = 0; i < 8; i++) {\n    tone(BUZZER, notes[i], 180);\n    Serial.print(\"Note \");\n    Serial.println(notes[i]);\n    delay(220);\n  }\n  noTone(BUZZER);\n  delay(1000);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"bz1","type":"buzzer","x":300,"y":40}],"wires":[["board:8","bz1:2"],["bz1:1","board:GND.1"]]}},{"id":"cloud-weather","name":"Live in ARGYNIX Cloud","summary":"A DHT22 sends to your Connect dashboards; Connect switches the LED.","open":"https://lab.argynix.com/bench?example=cloud-weather&run=1&view=3d","project":{"name":"Live in ARGYNIX Cloud","ide":"arduino","board":"arduino-uno","code":"// This board, live in ARGYNIX Cloud. Link it (Live in Cloud, top right) to a device\n// from Connect, press Run, and its readings reach that device's dashboards. A switch\n// in Connect sending \"setLed\" turns the LED on pin 13 on and off.\n#include <DHT.h>\n#include <ArgynixCloud.h>\n\nDHT dht(2, DHT22);\nArgynixCloud cloud;\nconst int LED = 13;\nunsigned long last = 0;\n\nvoid onCommand(const char *method, const char *params) {\n  if (strcmp(method, \"setLed\") == 0) {\n    bool on = strcmp(params, \"true\") == 0 || strcmp(params, \"1\") == 0;\n    digitalWrite(LED, on ? HIGH : LOW);\n    cloud.add(\"led\", on);\n    cloud.publish();\n    Serial.println(on ? \"LED on, from the cloud\" : \"LED off, from the cloud\");\n  }\n}\n\nvoid setup() {\n  Serial.begin(9600);\n  pinMode(LED, OUTPUT);\n  dht.begin();\n  cloud.onCommand(onCommand);\n  Serial.println(\"Sending a reading every 5 s\");\n}\n\nvoid loop() {\n  cloud.loop();\n  if (last == 0 || millis() - last >= 5000) {\n    last = millis() | 1;\n    float t = dht.readTemperature();\n    float h = dht.readHumidity();\n    if (!isnan(t) && !isnan(h)) {\n      cloud.add(\"temperature\", t, 1);\n      cloud.add(\"humidity\", h, 1);\n      cloud.publish();\n      Serial.print(\"Sent \");\n      Serial.print(t, 1);\n      Serial.print(\" C, \");\n      Serial.print(h, 0);\n      Serial.println(\" %\");\n    }\n  }\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"dht1","type":"dht22","x":420,"y":40},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":236,"y":92},{"id":"led1","type":"led","attrs":{"color":"green"},"x":316,"y":58}],"wires":[["board:13","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"],["dht1:VCC","board:5V"],["dht1:SDA","board:2"],["dht1:GND","board:GND.2"]]}},{"id":"servo","name":"Servo sweep","summary":"The Servo library on pin 9: the horn sweeps 0° to 180° and back.","open":"https://lab.argynix.com/bench?example=servo&run=1&view=3d","project":{"name":"Servo sweep","ide":"arduino","board":"arduino-uno","code":"// The Servo library on pin 9: the horn sweeps from 0 to 180 degrees and back.\n#include <Servo.h>\n\nServo servo;\n\nvoid setup() {\n  servo.attach(9);\n}\n\nvoid loop() {\n  for (int angle = 0; angle <= 180; angle += 2) {\n    servo.write(angle);\n    delay(15);\n  }\n  for (int angle = 180; angle >= 0; angle -= 2) {\n    servo.write(angle);\n    delay(15);\n  }\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"sv1","type":"servo","x":430,"y":290}],"wires":[["board:9","sv1:PWM"],["sv1:V+","board:5V"],["sv1:GND","board:GND.3"]]}},{"id":"distance","name":"Distance (HC-SR04)","summary":"An ultrasonic echo timed with pulseIn(). Set the distance in the inspector.","open":"https://lab.argynix.com/bench?example=distance&run=1&view=3d","project":{"name":"Distance (HC-SR04)","ide":"arduino","board":"arduino-uno","code":"// HC-SR04: a 10 µs pulse on TRIG, then ECHO stays HIGH for the sound's round trip.\n// 58 µs of echo is one centimetre. Select the sensor to set the distance.\n\nconst int TRIG = 3;\nconst int ECHO = 2;\n\nvoid setup() {\n  pinMode(TRIG, OUTPUT);\n  pinMode(ECHO, INPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  digitalWrite(TRIG, LOW);\n  delayMicroseconds(2);\n  digitalWrite(TRIG, HIGH);\n  delayMicroseconds(10);\n  digitalWrite(TRIG, LOW);\n  long echo = pulseIn(ECHO, HIGH, 30000);\n  Serial.print(\"distance:\");\n  Serial.println(echo / 58.2, 1);\n  delay(200);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"us1","type":"hc-sr04","x":360,"y":20}],"wires":[["us1:VCC","board:5V"],["us1:TRIG","board:3"],["us1:ECHO","board:2"],["us1:GND","board:GND.1"]]}},{"id":"weather","name":"Weather station","summary":"A DHT22 read every 2 s, shown on an I2C LCD and the serial port.","open":"https://lab.argynix.com/bench?example=weather&run=1&view=3d","project":{"name":"Weather station","ide":"arduino","board":"arduino-uno","code":"// A DHT22 on pin 2 and a 16x2 LCD on I2C (address 0x27, SDA A4, SCL A5).\n// Select the sensor to change the temperature and humidity.\n#include <DHT.h>\n#include <LiquidCrystal_I2C.h>\n\nDHT dht(2, DHT22);\nLiquidCrystal_I2C lcd(0x27, 16, 2);\n\nvoid setup() {\n  Serial.begin(9600);\n  dht.begin();\n  lcd.init();\n  lcd.backlight();\n  lcd.print(\"ARGYNIX Weather\");\n  delay(1000);\n}\n\nvoid loop() {\n  float t = dht.readTemperature();\n  float h = dht.readHumidity();\n  if (isnan(t) || isnan(h)) {\n    Serial.println(\"Sensor error\");\n    delay(2000);\n    return;\n  }\n  lcd.clear();\n  lcd.print(\"Temp: \");\n  lcd.print(t, 1);\n  lcd.print((char)223);\n  lcd.print(\"C\");\n  lcd.setCursor(0, 1);\n  lcd.print(\"Humidity: \");\n  lcd.print(h, 0);\n  lcd.print(\"%\");\n  Serial.print(\"temp:\");\n  Serial.print(t, 1);\n  Serial.print(\",humidity:\");\n  Serial.println(h, 1);\n  delay(2000);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"dht1","type":"dht22","x":400,"y":30},{"id":"lcd1","type":"lcd1602","attrs":{"pins":"i2c","address":"0x27"},"x":400,"y":290}],"wires":[["dht1:VCC","board:5V"],["dht1:SDA","board:2"],["dht1:GND","board:GND.1"],["lcd1:GND","board:GND.3"],["lcd1:VCC","board:5V"],["lcd1:SDA","board:A4"],["lcd1:SCL","board:A5"]]}},{"id":"oled","name":"OLED display","summary":"Adafruit GFX text and shapes on a 128x64 SSD1306 over I2C.","open":"https://lab.argynix.com/bench?example=oled&run=1&view=3d","project":{"name":"OLED display","ide":"arduino","board":"arduino-uno","code":"// A 128x64 SSD1306 OLED on I2C (address 0x3C): text and shapes with Adafruit GFX.\n#include <Wire.h>\n#include <Adafruit_GFX.h>\n#include <Adafruit_SSD1306.h>\n\nAdafruit_SSD1306 display(128, 64, &Wire, -1);\n\nvoid setup() {\n  Serial.begin(9600);\n  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {\n    Serial.println(\"No display\");\n    for (;;) {\n    }\n  }\n  display.clearDisplay();\n  display.drawRoundRect(0, 0, 128, 64, 6, SSD1306_WHITE);\n  display.setTextColor(SSD1306_WHITE);\n  display.setTextSize(2);\n  display.setCursor(22, 10);\n  display.print(\"ARGYNIX\");\n  display.setTextSize(1);\n  display.setCursor(56, 30);\n  display.print(\"Lab\");\n  display.display();\n}\n\nvoid loop() {\n  display.fillRect(8, 46, 112, 10, SSD1306_BLACK);\n  display.setCursor(12, 46);\n  display.print(\"Uptime: \");\n  display.print(millis() / 1000);\n  display.print(\" s\");\n  display.display();\n  delay(500);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"oled1","type":"ssd1306","attrs":{"address":"0x3C"},"x":380,"y":20}],"wires":[["oled1:DATA","board:A4"],["oled1:CLK","board:A5"],["oled1:VIN","board:5V"],["oled1:GND","board:GND.1"]]}},{"id":"keypad","name":"Keypad","summary":"A 4x4 keypad scanned with the Keypad library; each key on the serial port.","open":"https://lab.argynix.com/bench?example=keypad&run=1&view=3d","project":{"name":"Keypad","ide":"arduino","board":"arduino-uno","code":"// A 4x4 keypad: rows on pins 9..6, columns on 5..2. Click the keys while it runs.\n#include <Keypad.h>\n\nconst byte ROWS = 4;\nconst byte COLS = 4;\nchar keys[ROWS][COLS] = {\n  {'1', '2', '3', 'A'},\n  {'4', '5', '6', 'B'},\n  {'7', '8', '9', 'C'},\n  {'*', '0', '#', 'D'},\n};\nbyte rowPins[ROWS] = {9, 8, 7, 6};\nbyte colPins[COLS] = {5, 4, 3, 2};\n\nKeypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);\n\nvoid setup() {\n  Serial.begin(9600);\n  Serial.println(\"Press a key\");\n}\n\nvoid loop() {\n  char key = keypad.getKey();\n  if (key) {\n    Serial.print(\"Key: \");\n    Serial.println(key);\n  }\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"kp1","type":"membrane-keypad","x":380,"y":-150}],"wires":[["kp1:R1","board:9"],["kp1:R2","board:8"],["kp1:R3","board:7"],["kp1:R4","board:6"],["kp1:C1","board:5"],["kp1:C2","board:4"],["kp1:C3","board:3"],["kp1:C4","board:2"]]}},{"id":"seven-segment","name":"7-segment counter","summary":"A common-cathode digit on pins 2 to 8, counting 0 to 9.","open":"https://lab.argynix.com/bench?example=seven-segment&run=1&view=3d","project":{"name":"7-segment counter","ide":"arduino","board":"arduino-uno","code":"// A common-cathode 7-segment digit: segments A..G on pins 2..8, HIGH lights one.\n\nconst byte DIGITS[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};\n\nvoid show(int digit) {\n  for (int s = 0; s < 7; s++) digitalWrite(2 + s, (DIGITS[digit] >> s) & 1);\n}\n\nvoid setup() {\n  for (int pin = 2; pin <= 8; pin++) pinMode(pin, OUTPUT);\n}\n\nvoid loop() {\n  for (int d = 0; d < 10; d++) {\n    show(d);\n    delay(1000);\n  }\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"seg1","type":"7segment","attrs":{"common":"cathode","color":"red"},"x":400,"y":50},{"id":"rA","type":"resistor","attrs":{"value":"220"},"x":300,"y":14},{"id":"rB","type":"resistor","attrs":{"value":"220"},"x":300,"y":38},{"id":"rC","type":"resistor","attrs":{"value":"220"},"x":300,"y":62},{"id":"rD","type":"resistor","attrs":{"value":"220"},"x":300,"y":86},{"id":"rE","type":"resistor","attrs":{"value":"220"},"x":300,"y":110},{"id":"rF","type":"resistor","attrs":{"value":"220"},"x":300,"y":134},{"id":"rG","type":"resistor","attrs":{"value":"220"},"x":300,"y":158}],"wires":[["board:2","rA:1"],["rA:2","seg1:A"],["board:3","rB:1"],["rB:2","seg1:B"],["board:4","rC:1"],["rC:2","seg1:C"],["board:5","rD:1"],["rD:2","seg1:D"],["board:6","rE:1"],["rE:2","seg1:E"],["board:7","rF:1"],["rF:2","seg1:F"],["board:8","rG:1"],["rG:2","seg1:G"],["seg1:COM.1","board:GND.1"]]}},{"id":"night-light","name":"Night light","summary":"A photoresistor on A0: the darker it is, the brighter the LED.","open":"https://lab.argynix.com/bench?example=night-light&run=1&view=3d","project":{"name":"Night light","ide":"arduino","board":"arduino-uno","code":"// A photoresistor module on A0: it reads higher in the dark.\n// The LED on pin 9 is brighter the darker it gets. Select the sensor to set the light.\n\nvoid setup() {\n  pinMode(9, OUTPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  int raw = analogRead(A0);\n  analogWrite(9, map(raw, 0, 1023, 0, 255));\n  Serial.print(\"darkness:\");\n  Serial.println(raw);\n  delay(100);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"ldr1","type":"photoresistor-sensor","x":330,"y":470},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":250,"y":92},{"id":"led1","type":"led","attrs":{"color":"yellow"},"x":330,"y":58}],"wires":[["board:9","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"],["ldr1:VCC","board:5V"],["ldr1:GND","board:GND.3"],["ldr1:AO","board:A0"]]}},{"id":"thermometer","name":"Thermometer (NTC)","summary":"An NTC thermistor on A0, turned into °C. Watch it in the Plotter.","open":"https://lab.argynix.com/bench?example=thermometer&run=1&view=3d","project":{"name":"Thermometer (NTC)","ide":"arduino","board":"arduino-uno","code":"// An NTC thermistor module (10 kΩ, β 3950) on A0, turned into degrees Celsius.\n// Select the sensor to change the temperature; open the Plotter to watch it.\n\nconst float BETA = 3950;\n\nvoid setup() {\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  int a = analogRead(A0);\n  float celsius = 1 / (log(1 / (1023.0 / a - 1)) / BETA + 1.0 / 298.15) - 273.15;\n  Serial.print(\"celsius:\");\n  Serial.println(celsius, 1);\n  delay(500);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"ntc1","type":"ntc-temperature-sensor","x":400,"y":420}],"wires":[["ntc1:OUT","board:A0"],["ntc1:VCC","board:5V"],["ntc1:GND","board:GND.3"]]}},{"id":"rgb","name":"RGB mood light","summary":"A common-cathode RGB LED on PWM pins 9, 10 and 11, fading through colours.","open":"https://lab.argynix.com/bench?example=rgb&run=1&view=3d","project":{"name":"RGB mood light","ide":"arduino","board":"arduino-uno","code":"// A common-cathode RGB LED: red on 9, green on 10, blue on 11 (all PWM).\n// Each colour has its own resistor: 220 Ω for red, 100 Ω for green and blue (they drop more).\n\nvoid color(int r, int g, int b) {\n  analogWrite(9, r);\n  analogWrite(10, g);\n  analogWrite(11, b);\n}\n\nvoid setup() {\n}\n\nvoid loop() {\n  for (int i = 0; i < 255; i += 3) { color(255 - i, i, 0); delay(15); }\n  for (int i = 0; i < 255; i += 3) { color(0, 255 - i, i); delay(15); }\n  for (int i = 0; i < 255; i += 3) { color(i, 0, 255 - i); delay(15); }\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"rgb1","type":"rgb-led","attrs":{"common":"cathode"},"x":380,"y":50},{"id":"rR","type":"resistor","attrs":{"value":"220"},"x":290,"y":40},{"id":"rG","type":"resistor","attrs":{"value":"100"},"x":290,"y":80},{"id":"rB","type":"resistor","attrs":{"value":"100"},"x":290,"y":120}],"wires":[["board:9","rR:1"],["rR:2","rgb1:R"],["board:10","rG:1"],["rG:2","rgb1:G"],["board:11","rB:1"],["rB:2","rgb1:B"],["rgb1:COM","board:GND.1"]]}},{"id":"nano-blink","name":"Nano blink","summary":"The same Blink on an Arduino Nano, its LED on D13.","open":"https://lab.argynix.com/bench?example=nano-blink&run=1&view=3d","project":{"name":"Nano blink","ide":"arduino","board":"arduino-nano","code":"// Blink on an Arduino Nano: same chip as the Uno, smaller board.\n\nvoid setup() {\n  pinMode(13, OUTPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  digitalWrite(13, HIGH);\n  Serial.println(\"Hello from a Nano\");\n  delay(500);\n  digitalWrite(13, LOW);\n  delay(500);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-nano","x":80,"y":240},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":60,"y":140},{"id":"led1","type":"led","attrs":{"color":"green"},"x":150,"y":100}],"wires":[["board:13","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.2"]]}},{"id":"rotary-dial","name":"Rotary dial","summary":"An old phone’s dial: each digit counted from its pulses, a number built up on the serial monitor.","open":"https://lab.argynix.com/bench?example=rotary-dial&run=1&view=3d","project":{"name":"Rotary dial","ide":"arduino","board":"arduino-uno","code":"// A rotary dial, as an old phone has it. Click a digit on the dial while it runs.\n// DIAL closes to GND while the dial is away from rest; PULSE, closed at rest, opens\n// once for each count as it runs back (ten for 0). With the pull-ups on: DIAL reads\n// LOW while dialing, and PULSE goes HIGH once for each count.\nconst int DIAL = 2;\nconst int PULSE = 3;\nString number = \"\";\n\nvoid setup() {\n  Serial.begin(9600);\n  pinMode(DIAL, INPUT_PULLUP);\n  pinMode(PULSE, INPUT_PULLUP);\n  Serial.println(\"Dial a number.\");\n}\n\nvoid loop() {\n  if (digitalRead(DIAL) == HIGH) return;\n  int count = 0;\n  int last = digitalRead(PULSE);\n  while (digitalRead(DIAL) == LOW) {\n    int now = digitalRead(PULSE);\n    if (now == HIGH && last == LOW) count++;\n    last = now;\n    delay(5); // the contacts bounce less than this\n  }\n  int digit = count == 10 ? 0 : count;\n  number += String(digit);\n  Serial.print(\"Dialed \");\n  Serial.print(digit);\n  Serial.print(\", the number so far: \");\n  Serial.println(number);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"dial1","type":"rotary-dialer","x":380,"y":20}],"wires":[["dial1:DIAL","board:2"],["dial1:PULSE","board:3"],["dial1:GND","board:GND.1"]]}},{"id":"biaxial-clock","name":"Two hands, one axis","summary":"A biaxial stepper as a clock running fast: two A4988 drivers, the hour hand on the outer shaft, the minute hand on the inner, as a clock has them.","open":"https://lab.argynix.com/bench?example=biaxial-clock&run=1&view=3d","project":{"name":"Two hands, one axis","ide":"arduino","board":"arduino-uno","code":"// A biaxial stepper: two steppers on one axis, as a clock's hands. Each has an\n// A4988: a pulse on STEP is a step (1.8°, 200 a turn) the way DIR says.\n// This clock runs fast: a minute every tenth of a second.\nconst int MIN_STEP = 3, MIN_DIR = 2;\nconst int HOUR_STEP = 5, HOUR_DIR = 4;\nint minutes = 0;\n\nvoid step(int pin) {\n  digitalWrite(pin, HIGH);\n  delayMicroseconds(5);\n  digitalWrite(pin, LOW);\n}\n\nvoid setup() {\n  Serial.begin(9600);\n  for (int p = 2; p <= 5; p++) pinMode(p, OUTPUT);\n  digitalWrite(MIN_DIR, HIGH);\n  digitalWrite(HOUR_DIR, HIGH);\n}\n\nvoid loop() {\n  // 60 minutes a turn of the minute hand: 200 steps, so 10 steps every 3 minutes.\n  minutes++;\n  if (minutes % 3 == 0) for (int i = 0; i < 10; i++) step(MIN_STEP);\n  // 12 hours a turn of the hour hand: 200 steps in 720 minutes, a step every 3.6.\n  if ((minutes * 10) % 36 < 10) step(HOUR_STEP);\n  if (minutes % 60 == 0) {\n    Serial.print(minutes / 60);\n    Serial.println(\" o'clock\");\n  }\n  delay(100);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"drv1","type":"a4988","x":330,"y":60},{"id":"drv2","type":"a4988","x":330,"y":200},{"id":"stepper1","type":"biaxial-stepper","x":520,"y":40}],"wires":[["drv1:STEP","board:3"],["drv1:DIR","board:2"],["drv2:STEP","board:5"],["drv2:DIR","board:4"],["drv1:VDD","board:5V"],["drv1:GND","board:GND.1"],["drv2:VDD","board:5V"],["drv2:GND","board:GND.2"],["drv1:1A","stepper1:A2+"],["drv1:1B","stepper1:A2-"],["drv1:2A","stepper1:B2+"],["drv1:2B","stepper1:B2-"],["drv2:1A","stepper1:A1+"],["drv2:1B","stepper1:A1-"],["drv2:2A","stepper1:B1+"],["drv2:2B","stepper1:B1-"]]}},{"id":"two-unos-serial","name":"Two Unos over serial","summary":"Two boards, each with its own program: the first sends \"ping\" every half second, the second toggles its LED and answers \"pong\". Pick a board above the code to see its program; its serial monitor has a tab.","open":"https://lab.argynix.com/bench?example=two-unos-serial&run=1&view=3d","project":{"name":"Two Unos over serial","ide":"arduino","board":"arduino-uno","code":"// Board 1: sends a numbered ping on its TX (pin 1) every half second, and prints\n// what the other board answers on its RX (pin 0).\nint n = 0;\n\nvoid setup() {\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  Serial.print(\"ping \");\n  Serial.println(n++);\n  delay(500);\n  while (Serial.available()) {\n    String reply = Serial.readStringUntil('\\n');\n    reply.trim();\n    if (reply.length()) {\n      Serial.print(\"Board 2 says: \");\n      Serial.println(reply);\n    }\n  }\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":40,"y":200},{"id":"uno2","type":"arduino-uno","x":420,"y":200}],"wires":[["board:1","uno2:0"],["uno2:1","board:0"],["board:GND.1","uno2:GND.1"]]}},{"id":"i2c-two-unos","name":"Two Unos over I2C","summary":"Board 1 is the I2C controller (Wire.begin()), board 2 a target at address 8 (Wire.begin(8)). Board 1 sends its knob ten times a second; board 2 sets its LED to it and answers how many it has had.","open":"https://lab.argynix.com/bench?example=i2c-two-unos&run=1&view=3d","project":{"name":"Two Unos over I2C","ide":"arduino","board":"arduino-uno","code":"// Board 1, the I2C controller: sends the knob on A0 to board 2 (address 8) ten times a\n// second, and asks it how many levels it has had.\n#include <Wire.h>\n\nvoid setup() {\n  Serial.begin(9600);\n  Wire.begin();  // no address: the controller\n}\n\nvoid loop() {\n  byte level = analogRead(A0) / 4;\n  Wire.beginTransmission(8);\n  Wire.write(level);\n  byte status = Wire.endTransmission();  // 0: board 2 took it\n  Wire.requestFrom(8, 2);\n  unsigned int low = Wire.read();\n  unsigned int high = Wire.read();\n  Serial.print(\"knob \");\n  Serial.print(level);\n  Serial.print(status == 0 ? \", board 2 has had \" : \", board 2 did not answer, \");\n  Serial.println(low | (high << 8));\n  delay(100);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":40,"y":220},{"id":"uno2","type":"arduino-uno","x":470,"y":220},{"id":"p1","type":"potentiometer","x":60,"y":500},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":560,"y":90},{"id":"led1","type":"led","attrs":{"color":"green"},"x":640,"y":60}],"wires":[["board:A4","uno2:A4"],["board:A5","uno2:A5"],["board:GND.1","uno2:GND.1"],["p1:VCC","board:5V"],["p1:GND","board:GND.2"],["p1:SIG","board:A0"],["uno2:9","r1:1"],["r1:2","led1:A"],["led1:C","uno2:GND.3"]]}},{"id":"nrf24-two-unos","name":"Two Unos by radio (nRF24)","summary":"Each Uno has an nRF24L01+ (RF24). Board 1 sends its button 20 times a second to address \"00001\"; board 2 listens there and lights its LED while the button is held. The radios hear each other: same channel, data rate and address.","open":"https://lab.argynix.com/bench?example=nrf24-two-unos&run=1&view=3d","project":{"name":"Two Unos by radio (nRF24)","ide":"arduino","board":"arduino-uno","code":"// Board 1, the transmitter: sends its button (pin 2) to address \"00001\" 20 times a second.\n#include <SPI.h>\n#include <RF24.h>\n\nRF24 radio(7, 8);  // CE, CSN\nconst byte address[6] = \"00001\";\n\nvoid setup() {\n  Serial.begin(9600);\n  pinMode(2, INPUT_PULLUP);\n  if (!radio.begin()) Serial.println(\"The radio does not answer: check its wiring\");\n  radio.openWritingPipe(address);\n  radio.setPALevel(RF24_PA_MIN);\n  radio.stopListening();\n}\n\nvoid loop() {\n  byte pressed = digitalRead(2) == LOW;\n  bool ok = radio.write(&pressed, sizeof(pressed));\n  static byte was = 2;\n  if (pressed != was) {\n    Serial.print(pressed ? \"Pressed\" : \"Released\");\n    Serial.println(ok ? \", board 2 has it\" : \", nobody acknowledged\");\n    was = pressed;\n  }\n  delay(50);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":40,"y":250},{"id":"uno2","type":"arduino-uno","x":470,"y":250},{"id":"radio1","type":"nrf24l01","x":70,"y":40},{"id":"radio2","type":"nrf24l01","x":500,"y":40},{"id":"btn1","type":"pushbutton","attrs":{"color":"red"},"x":80,"y":520},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":520,"y":540},{"id":"led1","type":"led","attrs":{"color":"red"},"x":610,"y":510}],"wires":[["board:3.3V","radio1:VCC"],["board:GND.1","radio1:GND"],["board:7","radio1:CE"],["board:8","radio1:CSN"],["board:13","radio1:SCK"],["board:11","radio1:MOSI"],["board:12","radio1:MISO"],["uno2:3.3V","radio2:VCC"],["uno2:GND.1","radio2:GND"],["uno2:7","radio2:CE"],["uno2:8","radio2:CSN"],["uno2:13","radio2:SCK"],["uno2:11","radio2:MOSI"],["uno2:12","radio2:MISO"],["board:2","btn1:1.l"],["btn1:2.l","board:GND.2"],["uno2:3","r1:1"],["r1:2","led1:A"],["led1:C","uno2:GND.2"]]}},{"id":"esp-now-two-esp32","name":"Two ESP32s over ESP-NOW","summary":"ESP32 1 sends its button over ESP-NOW to every board (FF:FF:FF:FF:FF:FF); ESP32 2 lights its LED while it is held. Each board prints its own MAC: to send to one board, put its MAC in the sender (or set the receiver’s MAC in its settings).","open":"https://lab.argynix.com/bench?example=esp-now-two-esp32&run=1&view=3d","project":{"name":"Two ESP32s over ESP-NOW","ide":"arduino","board":"esp32-devkit-v1","code":"// ESP32 1: sends its button (GPIO 15) over ESP-NOW when it changes, and every half second\n// (a board that started later, or missed one, catches up), to every board\n// (FF:FF:FF:FF:FF:FF). To send to one board, put its MAC here instead: board 2 prints it.\n#include <esp_now.h>\n#include <WiFi.h>\n\nuint8_t to[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};\n\nvoid sent(const uint8_t *mac, esp_now_send_status_t status) {\n  Serial.println(status == ESP_NOW_SEND_SUCCESS ? \"Sent\" : \"Not delivered\");\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(15, INPUT_PULLUP);\n  WiFi.mode(WIFI_STA);\n  Serial.print(\"My MAC: \");\n  Serial.println(WiFi.macAddress());\n  if (esp_now_init() != ESP_OK) {\n    Serial.println(\"ESP-NOW did not start\");\n    return;\n  }\n  esp_now_register_send_cb(sent);\n  esp_now_peer_info_t peer = {};\n  memcpy(peer.peer_addr, to, 6);\n  peer.channel = 0;\n  peer.encrypt = false;\n  esp_now_add_peer(&peer);\n}\n\nvoid loop() {\n  static int was = -1;\n  static unsigned long last = 0;\n  uint8_t pressed = digitalRead(15) == LOW;\n  if (pressed != was || millis() - last >= 500) {\n    esp_now_send(to, &pressed, 1);\n    was = pressed;\n    last = millis();\n  }\n  delay(20);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":40,"y":80},{"id":"esp2","type":"esp32-devkit-v1","x":470,"y":80},{"id":"btn1","type":"pushbutton","attrs":{"color":"blue"},"x":80,"y":420},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":520,"y":440},{"id":"led1","type":"led","attrs":{"color":"blue"},"x":610,"y":410}],"wires":[["board:D15","btn1:1.l"],["btn1:2.l","board:GND.1"],["esp2:D4","r1:1"],["r1:2","led1:A"],["led1:C","esp2:GND.1"]]}},{"id":"ble-two-esp32","name":"Two ESP32s over Bluetooth LE","summary":"ESP32 1 is a BLE server with a knob, notified to whoever subscribes; ESP32 2 scans for its service, connects, subscribes, and dims its LED to the knob. The bench’s phone can connect to ESP32 1 too.","open":"https://lab.argynix.com/bench?example=ble-two-esp32&run=1&view=3d","project":{"name":"Two ESP32s over Bluetooth LE","ide":"arduino","board":"esp32-devkit-v1","code":"// ESP32 1: a Bluetooth LE server. Its knob (GPIO 34) is a characteristic, read and\n// notified when it moves; it advertises its service so a client finds it by that.\n#include <BLEDevice.h>\n#include <BLEServer.h>\n\n#define SERVICE \"6e400001-b5a3-f393-e0a9-e50e24dcca9e\"\n#define KNOB \"6e400003-b5a3-f393-e0a9-e50e24dcca9e\"\n\nBLECharacteristic *knob;\nint last = -1;\n\nclass Clients : public BLEServerCallbacks {\n  void onConnect(BLEServer *s) { Serial.println(\"A client connected\"); }\n  void onDisconnect(BLEServer *s) {\n    Serial.println(\"The client left: advertising again\");\n    BLEDevice::startAdvertising();\n  }\n};\n\nvoid setup() {\n  Serial.begin(115200);\n  BLEDevice::init(\"Knob\");\n  BLEServer *server = BLEDevice::createServer();\n  server->setCallbacks(new Clients());\n  BLEService *service = server->createService(SERVICE);\n  knob = service->createCharacteristic(KNOB, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);\n  service->start();\n  BLEDevice::getAdvertising()->addServiceUUID(SERVICE);\n  BLEDevice::startAdvertising();\n  Serial.print(\"Advertising as Knob, \");\n  Serial.println(BLEDevice::getAddress().toString());\n}\n\nvoid loop() {\n  int value = analogRead(34);\n  if (abs(value - last) > 40) {\n    last = value;\n    uint16_t v = value;\n    knob->setValue(v);\n    knob->notify();\n  }\n  delay(50);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":40,"y":80},{"id":"esp2","type":"esp32-devkit-v1","x":470,"y":80},{"id":"pot1","type":"potentiometer","x":60,"y":420},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":520,"y":440},{"id":"led1","type":"led","attrs":{"color":"blue"},"x":610,"y":410}],"wires":[["pot1:VCC","board:3V3"],["pot1:SIG","board:D34"],["pot1:GND","board:GND.1"],["esp2:D4","r1:1"],["r1:2","led1:A"],["led1:C","esp2:GND.1"]]}},{"id":"esp32-twai-uno-can","name":"ESP32 TWAI and Uno MCP2515 on CAN","summary":"The ESP32’s own CAN controller (TWAI, driver/twai.h) through an SN65HVD230 transceiver, and an Uno with an MCP2515, on one pair at 500 kbit/s. The ESP32 sends its knob; the Uno dims its LED to it and answers how many it has had.","open":"https://lab.argynix.com/bench?example=esp32-twai-uno-can&run=1&view=3d","project":{"name":"ESP32 TWAI and Uno MCP2515 on CAN","ide":"arduino","board":"esp32-devkit-v1","code":"// ESP32: its own CAN controller (TWAI) on GPIO 5 (TX) and GPIO 4 (RX), through the\n// SN65HVD230. Sends its knob (GPIO 34) as id 0x100 ten times a second, and prints what\n// the Uno answers (id 0x200).\n#include \"driver/twai.h\"\n\nvoid setup() {\n  Serial.begin(115200);\n  twai_general_config_t g = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_5, GPIO_NUM_4, TWAI_MODE_NORMAL);\n  twai_timing_config_t t = TWAI_TIMING_CONFIG_500KBITS();\n  twai_filter_config_t f = TWAI_FILTER_CONFIG_ACCEPT_ALL();\n  if (twai_driver_install(&g, &t, &f) == ESP_OK && twai_start() == ESP_OK) {\n    Serial.println(\"TWAI started at 500 kbit/s\");\n  } else {\n    Serial.println(\"TWAI did not start\");\n  }\n}\n\nvoid loop() {\n  int knob = analogRead(34);  // 0..4095\n  twai_message_t out = {};\n  out.identifier = 0x100;\n  out.data_length_code = 2;\n  out.data[0] = knob >> 8;\n  out.data[1] = knob & 0xff;\n  if (twai_transmit(&out, pdMS_TO_TICKS(50)) != ESP_OK) Serial.println(\"Not sent: is the Uno there?\");\n\n  twai_message_t in;\n  if (twai_receive(&in, pdMS_TO_TICKS(100)) == ESP_OK && in.identifier == 0x200) {\n    Serial.printf(\"Knob %d, the Uno has had %d\\n\", knob, in.data[0] | (in.data[1] << 8));\n  }\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":40,"y":140},{"id":"tr","type":"sn65hvd230","x":300,"y":60},{"id":"can","type":"mcp2515","attrs":{"crystal":"8"},"x":470,"y":40},{"id":"uno","type":"arduino-uno","x":660,"y":220},{"id":"p1","type":"potentiometer","x":60,"y":520},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":700,"y":520},{"id":"led1","type":"led","attrs":{"color":"yellow"},"x":790,"y":490}],"wires":[["board:3V3","tr:3V3"],["board:GND.1","tr:GND"],["board:D5","tr:CTX"],["board:D4","tr:CRX"],["tr:CANH","can:CANH"],["tr:CANL","can:CANL"],["uno:5V","can:VCC"],["uno:GND.1","can:GND"],["uno:10","can:CS"],["uno:11","can:SI"],["uno:12","can:SO"],["uno:13","can:SCK"],["uno:2","can:INT"],["p1:VCC","board:3V3"],["p1:GND","board:GND.2"],["p1:SIG","board:D34"],["uno:9","r1:1"],["r1:2","led1:A"],["led1:C","uno:GND.2"]]}},{"id":"can-bus-two-unos","name":"Two Unos on a CAN bus","summary":"Each Uno has an MCP2515 CAN module (mcp_can); their CANH and CANL are one pair. Board 1 sends a count and its knob every half second; board 2 prints each frame and lights its LED when the knob is past half way.","open":"https://lab.argynix.com/bench?example=can-bus-two-unos&run=1&view=3d","project":{"name":"Two Unos on a CAN bus","ide":"arduino","board":"arduino-uno","code":"// Board 1: sends a CAN frame every half second through its MCP2515 (CS on pin 10):\n// id 0x100, a count and the knob on A0. Board 2 shows what it gets.\n#include <SPI.h>\n#include <mcp_can.h>\n\nMCP_CAN CAN0(10);\nbyte count = 0;\n\nvoid setup() {\n  Serial.begin(115200);\n  // The common blue module has an 8 MHz crystal: name it, or the bit rate is not 500k.\n  if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) Serial.println(\"MCP2515 ready\");\n  else Serial.println(\"MCP2515 not found: check the wiring\");\n  CAN0.setMode(MCP_NORMAL);\n}\n\nvoid loop() {\n  int knob = analogRead(A0);\n  byte data[3] = { count++, highByte(knob), lowByte(knob) };\n  byte r = CAN0.sendMsgBuf(0x100, 0, 3, data);\n  Serial.print(r == CAN_OK ? \"Sent \" : \"Nobody acknowledged \");\n  Serial.print(data[0]);\n  Serial.print(\", knob \");\n  Serial.println(knob);\n  delay(500);\n}\n","files":[{"name":"libraries.txt","code":"mcp_can\n"}],"parts":[{"id":"board","type":"arduino-uno","x":40,"y":230},{"id":"uno2","type":"arduino-uno","x":470,"y":230},{"id":"can1","type":"mcp2515","attrs":{"crystal":"8"},"x":120,"y":40},{"id":"can2","type":"mcp2515","attrs":{"crystal":"8"},"x":550,"y":40},{"id":"p1","type":"potentiometer","x":60,"y":500}],"wires":[["board:5V","can1:VCC"],["board:GND.1","can1:GND"],["board:10","can1:CS"],["board:11","can1:SI"],["board:12","can1:SO"],["board:13","can1:SCK"],["board:2","can1:INT"],["uno2:5V","can2:VCC"],["uno2:GND.1","can2:GND"],["uno2:10","can2:CS"],["uno2:11","can2:SI"],["uno2:12","can2:SO"],["uno2:13","can2:SCK"],["uno2:2","can2:INT"],["can1:CANH","can2:CANH"],["can1:CANL","can2:CANL"],["p1:VCC","board:5V"],["p1:GND","board:GND.2"],["p1:SIG","board:A0"]]}},{"id":"esp32s3-rgb","name":"ESP32-S3: RGB LED","summary":"The S3 DevKitC-1’s own RGB LED (GPIO48) through the colours with rgbLedWrite().","open":"https://lab.argynix.com/bench?example=esp32s3-rgb&run=1&view=3d","project":{"name":"ESP32-S3: RGB LED","ide":"arduino","board":"esp32-s3-devkitc-1","code":"// ESP32-S3 DevKitC-1: its own RGB LED (GPIO48) through the colours with rgbLedWrite().\n\nconst uint8_t colours[][3] = {{255, 0, 0}, {255, 120, 0}, {0, 255, 0}, {0, 120, 255}, {160, 0, 255}};\n\nvoid setup() {\n  Serial.begin(115200);\n  Serial.printf(\"%s at %lu MHz, %d cores\\n\", ESP.getChipModel(), getCpuFrequencyMhz(), ESP.getChipCores());\n}\n\nvoid loop() {\n  for (auto &c : colours) {\n    rgbLedWrite(RGB_BUILTIN, c[0], c[1], c[2]);\n    delay(400);\n  }\n}\n","files":[],"parts":[{"id":"board","type":"esp32-s3-devkitc-1","x":100,"y":40}],"wires":[]}},{"id":"esp32c3-button","name":"ESP32-C3: button and RGB LED","summary":"A button on GPIO 4 steps the C3 DevKitM-1’s RGB LED through colours.","open":"https://lab.argynix.com/bench?example=esp32c3-button&run=1&view=3d","project":{"name":"ESP32-C3: button and RGB LED","ide":"arduino","board":"esp32-c3-devkitm-1","code":"// ESP32-C3 DevKitM-1: a button on GPIO 4 (to GND) steps its RGB LED (GPIO8) through colours.\nconst int BUTTON = 4;\nconst uint8_t colours[][3] = {{0, 0, 0}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 255}};\nint colour = 0;\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(BUTTON, INPUT_PULLUP);\n}\n\nvoid loop() {\n  static bool was = HIGH;\n  bool now = digitalRead(BUTTON);\n  if (was == HIGH && now == LOW) {\n    colour = (colour + 1) % 5;\n    rgbLedWrite(RGB_BUILTIN, colours[colour][0], colours[colour][1], colours[colour][2]);\n    Serial.printf(\"colour %d\\n\", colour);\n  }\n  was = now;\n  delay(10);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-c3-devkitm-1","x":100,"y":40},{"id":"b1","type":"pushbutton","attrs":{"color":"green"},"x":290,"y":170}],"wires":[["board:4","b1:1.l"],["b1:2.l","board:GND.9"]]}},{"id":"esp32h2-lcd","name":"ESP32-H2: LCD, no Wi-Fi","summary":"The H2 has BLE and Thread, no Wi-Fi: an I2C LCD on SDA 12, SCL 22 counts up.","open":"https://lab.argynix.com/bench?example=esp32h2-lcd&run=1&view=3d","project":{"name":"ESP32-H2: LCD, no Wi-Fi","ide":"arduino","board":"esp32-h2-devkitm-1","code":"// ESP32-H2 DevKitM-1 (no Wi-Fi: BLE, Thread, Zigbee). An I2C LCD on its default pins\n// (SDA 12, SCL 22) counts the seconds; the RGB LED (GPIO8) breathes.\n#include <LiquidCrystal_I2C.h>\n\nLiquidCrystal_I2C lcd(0x27, 16, 2);\n\nvoid setup() {\n  lcd.init();\n  lcd.backlight();\n  lcd.print(\"ESP32-H2 online\");\n}\n\nvoid loop() {\n  lcd.setCursor(0, 1);\n  lcd.print(\"Up \");\n  lcd.print(millis() / 1000);\n  lcd.print(\" s   \");\n  for (int i = 0; i < 64; i += 4) {\n    rgbLedWrite(RGB_BUILTIN, 0, i, i * 2);\n    delay(30);\n  }\n  for (int i = 64; i > 0; i -= 4) {\n    rgbLedWrite(RGB_BUILTIN, 0, i, i * 2);\n    delay(30);\n  }\n}\n","files":[],"parts":[{"id":"board","type":"esp32-h2-devkitm-1","x":100,"y":40},{"id":"lcd1","type":"lcd1602","attrs":{"pins":"i2c","address":"0x27"},"x":290,"y":150}],"wires":[["lcd1:SDA","board:12"],["lcd1:SCL","board:22"],["lcd1:VCC","board:5V"],["lcd1:GND","board:GND.4"]]}},{"id":"pico-fade","name":"Pico: blink and breathe","summary":"The Pico’s own LED blinks, an LED on GP15 breathes with PWM, the knob on GP26 sets the pace.","open":"https://lab.argynix.com/bench?example=pico-fade&run=1&view=3d","project":{"name":"Pico: blink and breathe","ide":"arduino","board":"pi-pico","code":"// Raspberry Pi Pico: its own LED (GP25) blinks, an LED on GP15 breathes with PWM, and\n// the knob on GP26 (A0) sets how fast. Pins are GP numbers, as Arduino-Pico has them.\nconst int FADE_LED = 15;\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(LED_BUILTIN, OUTPUT);\n  analogWriteFreq(1000);\n  analogWriteRange(255);\n  Serial.printf(\"Pico at %lu MHz\\n\", rp2040.f_cpu() / 1000000);\n}\n\nvoid loop() {\n  int knob = analogRead(A0);  // 0..1023\n  int step = map(knob, 0, 1023, 1, 12);\n  for (int level = 0; level <= 255; level += step) {\n    analogWrite(FADE_LED, level);\n    delay(8);\n  }\n  for (int level = 255; level >= 0; level -= step) {\n    analogWrite(FADE_LED, level);\n    delay(8);\n  }\n  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));\n  Serial.printf(\"knob %d, step %d\\n\", knob, step);\n}\n","files":[],"parts":[{"id":"board","type":"pi-pico","x":260,"y":30},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":180,"y":229},{"id":"led1","type":"led","attrs":{"color":"green"},"x":120,"y":190},{"id":"pot1","type":"potentiometer","x":420,"y":90}],"wires":[["r1:2","board:GP15"],["led1:A","r1:1"],["led1:C","board:GND.4"],["pot1:VCC","board:3V3"],["pot1:GND","board:GND.5"],["pot1:SIG","board:GP26"]]}},{"id":"picow-cloud","name":"Pico W: knob to the cloud","summary":"The Pico W on Wi-Fi sends its knob to ARGYNIX Cloud; Connect switches its LED.","open":"https://lab.argynix.com/bench?example=picow-cloud&run=1&view=3d","project":{"name":"Pico W: knob to the cloud","ide":"arduino","board":"pi-pico-w","code":"// Raspberry Pi Pico W on Wi-Fi, live in ARGYNIX Cloud. The knob on GP26 is sent every\n// 2 s. Link the project (Live in Cloud, top right) to a device from Connect; a switch\n// there sending \"setLed\" lights the Pico W's own LED.\n#include <WiFi.h>\n#include <ArgynixCloud.h>\n\nArgynixCloud cloud;\nunsigned long last = 0;\n\nvoid onCommand(const char *method, const char *params) {\n  if (strcmp(method, \"setLed\") == 0) {\n    bool on = strcmp(params, \"true\") == 0 || strcmp(params, \"1\") == 0;\n    digitalWrite(LED_BUILTIN, on);\n    cloud.add(\"led\", on);\n    cloud.publish();\n  }\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(LED_BUILTIN, OUTPUT);\n  WiFi.begin(\"ARGYNIX-Lab\", \"\");\n  while (WiFi.status() != WL_CONNECTED) delay(100);\n  Serial.print(\"Wi-Fi up, IP \");\n  Serial.println(WiFi.localIP());\n  cloud.onCommand(onCommand);\n}\n\nvoid loop() {\n  cloud.loop();\n  if (last == 0 || millis() - last >= 2000) {\n    last = millis() | 1;\n    cloud.add(\"level\", analogRead(A0) * 100L / 1023);\n    cloud.add(\"rssi\", (long)WiFi.RSSI());\n    cloud.publish();\n  }\n  delay(10);\n}\n","files":[],"parts":[{"id":"board","type":"pi-pico-w","x":260,"y":30},{"id":"pot1","type":"potentiometer","x":420,"y":90}],"wires":[["pot1:VCC","board:3V3"],["pot1:GND","board:GND.5"],["pot1:SIG","board:GP26"]]}},{"id":"bluepill-button","name":"Blue Pill: button interrupt","summary":"A button on PB12 toggles the PC13 LED through an interrupt; the LED lights on LOW.","open":"https://lab.argynix.com/bench?example=bluepill-button&run=1&view=3d","project":{"name":"Blue Pill: button interrupt","ide":"arduino","board":"stm32-bluepill","code":"// STM32 Blue Pill: a button on PB12 (to GND) toggles the PC13 LED through an interrupt.\n// The LED is wired to 3.3 V, so it lights when PC13 is LOW. Pins by their STM32 names.\nconst int BUTTON = PB12;\nvolatile int presses = 0;\n\nvoid pressed() { presses++; }\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(LED_BUILTIN, OUTPUT);\n  digitalWrite(LED_BUILTIN, HIGH);  // off\n  pinMode(BUTTON, INPUT_PULLUP);\n  attachInterrupt(digitalPinToInterrupt(BUTTON), pressed, FALLING);\n  Serial.print(\"Blue Pill at \");\n  Serial.print(F_CPU / 1000000);\n  Serial.println(\" MHz\");\n}\n\nvoid loop() {\n  static int seen = 0;\n  if (presses != seen) {\n    seen = presses;\n    digitalToggle(LED_BUILTIN);\n    Serial.print(\"Pressed \");\n    Serial.print(seen);\n    Serial.println(digitalRead(LED_BUILTIN) == LOW ? \" times, LED on\" : \" times, LED off\");\n  }\n  delay(5);\n}\n","files":[],"parts":[{"id":"board","type":"stm32-bluepill","x":220,"y":30},{"id":"b1","type":"pushbutton","attrs":{"color":"yellow"},"x":90,"y":50}],"wires":[["b1:1.r","board:PB12"],["b1:2.r","board:GND.1"]]}},{"id":"nucleo-lcd","name":"Nucleo-F401RE: knob on an LCD","summary":"An I2C LCD on D14/D15 shows the knob on A0 in volts; LD2 blinks by its STM32 name, PA5.","open":"https://lab.argynix.com/bench?example=nucleo-lcd&run=1&view=3d","project":{"name":"Nucleo-F401RE: knob on an LCD","ide":"arduino","board":"nucleo-f401re","code":"// STM32 Nucleo-F401RE: an I2C LCD on D14 (SDA) and D15 (SCL) shows the knob on A0 in\n// volts, read at 12 bits. LD2 is D13, which is also PA5: either name drives it.\n#include <Wire.h>\n#include <LiquidCrystal_I2C.h>\n\nLiquidCrystal_I2C lcd(0x27, 16, 2);\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(LED_BUILTIN, OUTPUT);\n  analogReadResolution(12);\n  lcd.init();\n  lcd.backlight();\n  lcd.print(\"Nucleo-F401RE\");\n}\n\nvoid loop() {\n  int raw = analogRead(A0);  // 0..4095\n  float volts = raw * 3.3f / 4095.0f;\n  lcd.setCursor(0, 1);\n  lcd.print(\"A0 \");\n  lcd.print(volts, 2);\n  lcd.print(\" V   \");\n  digitalWrite(PA5, (millis() / 500) % 2);\n  Serial.println(volts, 2);\n  delay(100);\n}\n","files":[],"parts":[{"id":"board","type":"nucleo-f401re","x":40,"y":260},{"id":"lcd1","type":"lcd1602","attrs":{"pins":"i2c","address":"0x27"},"x":400,"y":40},{"id":"pot1","type":"potentiometer","x":430,"y":330}],"wires":[["lcd1:SDA","board:D14"],["lcd1:SCL","board:D15"],["lcd1:VCC","board:5V"],["lcd1:GND","board:GND.1"],["pot1:VCC","board:3V3"],["pot1:GND","board:GND.2"],["pot1:SIG","board:A0"]]}},{"id":"unor4-adc","name":"Uno R4: 14-bit knob","summary":"The Uno R4 Minima reads the knob at 14 bits and dims an LED on D9 with it.","open":"https://lab.argynix.com/bench?example=unor4-adc&run=1&view=3d","project":{"name":"Uno R4: 14-bit knob","ide":"arduino","board":"arduino-uno-r4-minima","code":"// Arduino Uno R4 Minima: its ADC reads up to 14 bits. The knob on A0 is read at 14 bits\n// (0 to 16383 over 5 V) and dims the LED on D9. The R4's pins give 8 mA each (the classic\n// Uno's give 20), so the LED has 470 Ω, not 220.\nvoid setup() {\n  Serial.begin(115200);\n  analogReadResolution(14);\n  pinMode(9, OUTPUT);\n}\n\nvoid loop() {\n  int raw = analogRead(A0);\n  analogWrite(9, raw >> 6);  // 0..255\n  Serial.print(\"A0: \");\n  Serial.print(raw);\n  Serial.print(\" of 16383, \");\n  Serial.print(raw * 5.0 / 16383, 2);\n  Serial.println(\" V\");\n  delay(200);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno-r4-minima","x":60,"y":200},{"id":"r1","type":"resistor","attrs":{"value":"470"},"x":240,"y":140},{"id":"led1","type":"led","attrs":{"color":"orange"},"x":300,"y":100},{"id":"pot1","type":"potentiometer","x":380,"y":330}],"wires":[["board:9","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"],["pot1:VCC","board:5V"],["pot1:GND","board:GND.2"],["pot1:SIG","board:A0"]]}},{"id":"promini-blink","name":"Pro Mini: blink","summary":"The Pro Mini’s real ATmega328P blinks LED 13 and counts its uptime.","open":"https://lab.argynix.com/bench?example=promini-blink&run=1&view=3d","project":{"name":"Pro Mini: blink","ide":"arduino","board":"arduino-pro-mini","code":"// Arduino Pro Mini (5 V, 16 MHz): the real ATmega328P, as on the Uno. LED 13 blinks and\n// the uptime goes to Serial (the TXO pin; the Lab shows it in Serial).\nvoid setup() {\n  Serial.begin(9600);\n  pinMode(LED_BUILTIN, OUTPUT);\n}\n\nvoid loop() {\n  digitalWrite(LED_BUILTIN, HIGH);\n  delay(500);\n  digitalWrite(LED_BUILTIN, LOW);\n  delay(500);\n  Serial.print(\"Up \");\n  Serial.print(millis() / 1000);\n  Serial.println(\" s\");\n}\n","files":[],"parts":[{"id":"board","type":"arduino-pro-mini","x":160,"y":60}],"wires":[]}},{"id":"mega-bar","name":"Mega: light chase","summary":"A 10-LED bar graph on the Mega’s pins 22 to 31; the knob on A8 sets the speed.","open":"https://lab.argynix.com/bench?example=mega-bar&run=1&view=3d","project":{"name":"Mega: light chase","ide":"arduino","board":"arduino-mega","code":"// The Mega's extra pins: a 10-LED bar graph on pins 22 to 31 chases its light.\n// The knob on A8 (one of the Mega's 16 analog inputs) sets the speed.\n// One LED is lit at a time, so one 220 Ω resistor on the shared cathodes limits them all.\n\nvoid setup() {\n  for (int p = 22; p <= 31; p++) pinMode(p, OUTPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  for (int i = 0; i < 10; i++) {\n    for (int p = 0; p < 10; p++) digitalWrite(22 + p, p == i);\n    delay(map(analogRead(A8), 0, 1023, 20, 300));\n  }\n  Serial.print(\"knob:\");\n  Serial.println(analogRead(A8));\n}\n","files":[],"parts":[{"id":"board","type":"arduino-mega","x":40,"y":260},{"id":"bar1","type":"led-bar-graph","attrs":{"color":"green"},"x":520,"y":250},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":600,"y":420},{"id":"pot1","type":"potentiometer","x":470,"y":500}],"wires":[["board:22","bar1:A1"],["board:23","bar1:A2"],["board:24","bar1:A3"],["board:25","bar1:A4"],["board:26","bar1:A5"],["board:27","bar1:A6"],["board:28","bar1:A7"],["board:29","bar1:A8"],["board:30","bar1:A9"],["board:31","bar1:A10"],["bar1:C1","bar1:C2"],["bar1:C2","bar1:C3"],["bar1:C3","bar1:C4"],["bar1:C4","bar1:C5"],["bar1:C5","bar1:C6"],["bar1:C6","bar1:C7"],["bar1:C7","bar1:C8"],["bar1:C8","bar1:C9"],["bar1:C9","bar1:C10"],["bar1:C10","r1:1"],["r1:2","board:GND.5"],["pot1:VCC","board:5V"],["pot1:GND","board:GND.3"],["pot1:SIG","board:A8"]]}},{"id":"esp32-blink","name":"ESP32: blink and fade","summary":"The blue LED on GPIO 2 blinks; an LED on GPIO 4 fades with LEDC PWM.","open":"https://lab.argynix.com/bench?example=esp32-blink&run=1&view=3d","project":{"name":"ESP32: blink and fade","ide":"arduino","board":"esp32-devkit-v1","code":"// ESP32: the blue LED on GPIO 2 blinks, and an LED on GPIO 4 fades with LEDC PWM.\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(LED_BUILTIN, OUTPUT);\n  ledcAttach(4, 5000, 8);\n  Serial.printf(\"ESP32 ready at %lu MHz\\n\", getCpuFrequencyMhz());\n}\n\nvoid loop() {\n  digitalWrite(LED_BUILTIN, HIGH);\n  for (int d = 0; d <= 255; d += 5) {\n    ledcWrite(4, d);\n    delay(10);\n  }\n  digitalWrite(LED_BUILTIN, LOW);\n  for (int d = 255; d >= 0; d -= 5) {\n    ledcWrite(4, d);\n    delay(10);\n  }\n  Serial.printf(\"uptime %lu ms\\n\", millis());\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":80,"y":120},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":230,"y":170},{"id":"led1","type":"led","attrs":{"color":"blue"},"x":310,"y":140}],"wires":[["board:D4","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"]]}},{"id":"esp32-cloud","name":"ESP32: weather to the cloud","summary":"Wi-Fi, a DHT22 and an I2C LCD; readings to ARGYNIX Cloud, its LED switched from Connect.","open":"https://lab.argynix.com/bench?example=esp32-cloud&run=1&view=3d","project":{"name":"ESP32: weather to the cloud","ide":"arduino","board":"esp32-devkit-v1","code":"// ESP32 on Wi-Fi, live in ARGYNIX Cloud. A DHT22 on GPIO 4 is read every 5 s, shown on\n// an I2C LCD (SDA 21, SCL 22) and sent to the cloud. Link the project (Live in Cloud,\n// top right) to a device from Connect; a switch there sending \"setLed\" lights GPIO 2.\n#include <WiFi.h>\n#include <DHT.h>\n#include <LiquidCrystal_I2C.h>\n#include <ArgynixCloud.h>\n\nDHT dht(4, DHT22);\nLiquidCrystal_I2C lcd(0x27, 16, 2);\nArgynixCloud cloud;\nunsigned long last = 0;\n\nvoid onCommand(const char *method, const char *params) {\n  if (strcmp(method, \"setLed\") == 0) {\n    bool on = strcmp(params, \"true\") == 0 || strcmp(params, \"1\") == 0;\n    digitalWrite(LED_BUILTIN, on);\n    cloud.add(\"led\", on);\n    cloud.publish();\n  }\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(LED_BUILTIN, OUTPUT);\n  lcd.init();\n  lcd.backlight();\n  lcd.print(\"Joining Wi-Fi...\");\n  WiFi.begin(\"ARGYNIX-Lab\", \"\");\n  while (WiFi.status() != WL_CONNECTED) delay(100);\n  Serial.print(\"Wi-Fi up, IP \");\n  Serial.println(WiFi.localIP());\n  dht.begin();\n  cloud.onCommand(onCommand);\n}\n\nvoid loop() {\n  cloud.loop();\n  if (last == 0 || millis() - last >= 5000) {\n    last = millis() | 1;\n    float t = dht.readTemperature();\n    float h = dht.readHumidity();\n    if (!isnan(t) && !isnan(h)) {\n      lcd.clear();\n      lcd.print(\"Temp \");\n      lcd.print(t, 1);\n      lcd.print((char)223);\n      lcd.print(\"C\");\n      lcd.setCursor(0, 1);\n      lcd.print(\"Humidity \");\n      lcd.print(h, 0);\n      lcd.print(\"%\");\n      cloud.add(\"temperature\", t, 1);\n      cloud.add(\"humidity\", h, 1);\n      cloud.add(\"rssi\", (long)WiFi.RSSI());\n      cloud.publish();\n    }\n  }\n  delay(10);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":80,"y":120},{"id":"dht1","type":"dht22","x":300,"y":40},{"id":"lcd1","type":"lcd1602","attrs":{"pins":"i2c","address":"0x27"},"x":300,"y":260}],"wires":[["dht1:VCC","board:3V3"],["dht1:SDA","board:D4"],["dht1:GND","board:GND.1"],["lcd1:SDA","board:D21"],["lcd1:SCL","board:D22"],["lcd1:VCC","board:VIN"],["lcd1:GND","board:GND.2"]]}},{"id":"esp32-neopixel","name":"ESP32: NeoPixel rainbow","summary":"A 16-pixel ring on GPIO 5 runs a rainbow with Adafruit_NeoPixel.","open":"https://lab.argynix.com/bench?example=esp32-neopixel&run=1&view=3d","project":{"name":"ESP32: NeoPixel rainbow","ide":"arduino","board":"esp32-devkit-v1","code":"// A NeoPixel ring on GPIO 5 runs a rainbow (Adafruit_NeoPixel).\n#include <Adafruit_NeoPixel.h>\n\nAdafruit_NeoPixel ring(16, 5, NEO_GRB + NEO_KHZ800);\n\nvoid setup() {\n  ring.begin();\n  ring.setBrightness(90);\n}\n\nvoid loop() {\n  for (long hue = 0; hue < 65536; hue += 768) {\n    for (int i = 0; i < ring.numPixels(); i++) {\n      ring.setPixelColor(i, ring.gamma32(ring.ColorHSV(hue + i * 65536L / ring.numPixels())));\n    }\n    ring.show();\n    delay(20);\n  }\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":80,"y":120},{"id":"ring1","type":"led-ring","attrs":{"pixels":"16"},"x":260,"y":40}],"wires":[["ring1:DIN","board:D5"],["ring1:VCC","board:VIN"],["ring1:GND","board:GND.1"]]}},{"id":"neopixel-ring","name":"NeoPixel ring","summary":"A 16-pixel WS2812 ring on pin 6: a spinning comet.","open":"https://lab.argynix.com/bench?example=neopixel-ring&run=1&view=3d","project":{"name":"NeoPixel ring","ide":"arduino","board":"arduino-uno","code":"// A 16-pixel NeoPixel ring on pin 6: a comet goes round.\n#include <Adafruit_NeoPixel.h>\n\nAdafruit_NeoPixel ring(16, 6, NEO_GRB + NEO_KHZ800);\nint head = 0;\n\nvoid setup() {\n  ring.begin();\n  ring.setBrightness(120);\n}\n\nvoid loop() {\n  ring.clear();\n  for (int t = 0; t < 5; t++) {\n    int i = (head - t + 16) % 16;\n    ring.setPixelColor(i, ring.Color(255 >> t, 80 >> t, 255 >> (t + 1)));\n  }\n  ring.show();\n  head = (head + 1) % 16;\n  delay(60);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"ring1","type":"led-ring","attrs":{"pixels":"16"},"x":330,"y":20}],"wires":[["ring1:DIN","board:6"],["ring1:VCC","board:5V"],["ring1:GND","board:GND.1"]]}},{"id":"encoder","name":"Rotary encoder","summary":"A KY-040 counted with an interrupt on CLK; press to reset.","open":"https://lab.argynix.com/bench?example=encoder&run=1&view=3d","project":{"name":"Rotary encoder","ide":"arduino","board":"arduino-uno","code":"// KY-040 rotary encoder: an interrupt on CLK counts the detents; press it to reset.\nconst int CLK = 2;\nconst int DT = 3;\nconst int SW = 4;\nvolatile long count = 0;\n\nvoid onClk() {\n  if (digitalRead(CLK) == LOW) count += digitalRead(DT) == HIGH ? 1 : -1;\n}\n\nvoid setup() {\n  pinMode(CLK, INPUT_PULLUP);\n  pinMode(DT, INPUT_PULLUP);\n  pinMode(SW, INPUT_PULLUP);\n  attachInterrupt(digitalPinToInterrupt(CLK), onClk, FALLING);\n  Serial.begin(9600);\n  Serial.println(\"Turn the knob\");\n}\n\nvoid loop() {\n  static long shown = 0;\n  if (digitalRead(SW) == LOW) count = 0;\n  if (count != shown) {\n    shown = count;\n    Serial.print(\"count:\");\n    Serial.println(shown);\n  }\n  delay(5);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"enc1","type":"ky-040","x":360,"y":60}],"wires":[["enc1:CLK","board:2"],["enc1:DT","board:3"],["enc1:SW","board:4"],["enc1:VCC","board:5V"],["enc1:GND","board:GND.1"]]}},{"id":"mpu6050","name":"Tilt (MPU6050)","summary":"Acceleration and rotation over I2C, read with Wire. Tilt it in the inspector.","open":"https://lab.argynix.com/bench?example=mpu6050&run=1&view=3d","project":{"name":"Tilt (MPU6050)","ide":"arduino","board":"arduino-uno","code":"// MPU6050 over I2C (address 0x68): wake it, then read acceleration (g) and rotation (°/s).\n#include <Wire.h>\n\nconst int MPU = 0x68;\n\nint16_t next16() {\n  int16_t hi = Wire.read();\n  int16_t lo = Wire.read();\n  return (hi << 8) | lo;\n}\n\nvoid setup() {\n  Serial.begin(9600);\n  Wire.begin();\n  Wire.beginTransmission(MPU);\n  Wire.write(0x6B);\n  Wire.write(0);\n  Wire.endTransmission();\n}\n\nvoid loop() {\n  Wire.beginTransmission(MPU);\n  Wire.write(0x3B);\n  Wire.endTransmission(false);\n  Wire.requestFrom(MPU, 14);\n  float ax = next16() / 16384.0;\n  float ay = next16() / 16384.0;\n  float az = next16() / 16384.0;\n  next16();\n  float gx = next16() / 131.0;\n  Serial.print(\"ax:\");\n  Serial.print(ax, 2);\n  Serial.print(\",ay:\");\n  Serial.print(ay, 2);\n  Serial.print(\",az:\");\n  Serial.print(az, 2);\n  Serial.print(\",gx:\");\n  Serial.println(gx, 1);\n  delay(200);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"imu1","type":"mpu6050","attrs":{"address":"0x68"},"x":360,"y":80}],"wires":[["imu1:SDA","board:A4.2"],["imu1:SCL","board:A5.2"],["imu1:GND","board:GND.1"],["imu1:VCC","board:5V"]]}},{"id":"clock","name":"Clock (DS1307 + LCD)","summary":"RTClib reads a DS1307; the time and date on an I2C LCD.","open":"https://lab.argynix.com/bench?example=clock&run=1&view=3d","project":{"name":"Clock (DS1307 + LCD)","ide":"arduino","board":"arduino-uno","code":"// A DS1307 clock and a 16x2 LCD, both on I2C. RTClib reads the time.\n#include <RTClib.h>\n#include <LiquidCrystal_I2C.h>\n\nRTC_DS1307 rtc;\nLiquidCrystal_I2C lcd(0x27, 16, 2);\n\nvoid setup() {\n  Serial.begin(9600);\n  lcd.init();\n  lcd.backlight();\n  if (!rtc.begin()) {\n    lcd.print(\"No clock found\");\n    while (true) {\n    }\n  }\n}\n\nvoid loop() {\n  DateTime now = rtc.now();\n  char line[17];\n  snprintf(line, sizeof(line), \"%02d:%02d:%02d\", now.hour(), now.minute(), now.second());\n  lcd.setCursor(4, 0);\n  lcd.print(line);\n  snprintf(line, sizeof(line), \"%04d-%02d-%02d\", now.year(), now.month(), now.day());\n  lcd.setCursor(3, 1);\n  lcd.print(line);\n  Serial.println(line);\n  delay(1000);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"rtc1","type":"ds1307","x":360,"y":40},{"id":"lcd1","type":"lcd1602","attrs":{"pins":"i2c","address":"0x27"},"x":380,"y":300}],"wires":[["rtc1:SDA","board:A4.2"],["rtc1:SCL","board:A5.2"],["rtc1:5V","board:5V"],["rtc1:GND","board:GND.1"],["lcd1:SDA","board:A4"],["lcd1:SCL","board:A5"],["lcd1:VCC","board:5V"],["lcd1:GND","board:GND.3"]]}},{"id":"scale","name":"Scale (HX711)","summary":"A load cell through an HX711: tared at start, then grams. Set the weight.","open":"https://lab.argynix.com/bench?example=scale&run=1&view=3d","project":{"name":"Scale (HX711)","ide":"arduino","board":"arduino-uno","code":"// A load cell through an HX711: tared at start, then read in grams.\n// Select the load cell to put a weight on it.\n#include <HX711.h>\n\nHX711 scale;\n\nvoid setup() {\n  Serial.begin(9600);\n  scale.begin(3, 2);\n  scale.set_scale(420);\n  scale.tare(5);\n  Serial.println(\"Tared\");\n}\n\nvoid loop() {\n  Serial.print(\"grams:\");\n  Serial.println(scale.get_units(3), 0);\n  delay(250);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"scale1","type":"hx711","attrs":{"type":"5kg"},"x":340,"y":20}],"wires":[["scale1:DT","board:3"],["scale1:SCK","board:2"],["scale1:VCC","board:5V"],["scale1:GND","board:GND.1"]]}},{"id":"stepper","name":"Stepper motor","summary":"The Stepper library on pins 8 to 11: one turn clockwise, then back.","open":"https://lab.argynix.com/bench?example=stepper&run=1&view=3d","project":{"name":"Stepper motor","ide":"arduino","board":"arduino-uno","code":"// A bipolar stepper on pins 8 to 11 with the Stepper library (200 steps a turn):\n// one turn clockwise, then back.\n#include <Stepper.h>\n\nStepper motor(200, 8, 9, 10, 11);\n\nvoid setup() {\n  motor.setSpeed(60);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  Serial.println(\"One turn clockwise\");\n  motor.step(200);\n  delay(500);\n  Serial.println(\"And back\");\n  motor.step(-200);\n  delay(500);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"m1","type":"stepper-motor","x":340,"y":-70}],"wires":[["m1:A+","board:8"],["m1:A-","board:9"],["m1:B+","board:10"],["m1:B-","board:11"]]}},{"id":"gas-alarm","name":"Gas alarm (MQ-2)","summary":"The MQ-2’s level on A0, its alarm on pin 7; a buzzer sounds. Raise the gas.","open":"https://lab.argynix.com/bench?example=gas-alarm&run=1&view=3d","project":{"name":"Gas alarm (MQ-2)","ide":"arduino","board":"arduino-uno","code":"// An MQ-2 gas sensor: AOUT on A0 for the level, DOUT on pin 7 for the alarm (LOW above\n// its threshold). The buzzer on pin 8 sounds while it is. Raise the gas in the inspector.\nconst int ALARM = 7;\nconst int BUZZER = 8;\n\nvoid setup() {\n  pinMode(ALARM, INPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  int level = analogRead(A0);\n  bool gas = digitalRead(ALARM) == LOW;\n  if (gas) tone(BUZZER, 2000);\n  else noTone(BUZZER);\n  Serial.print(\"gas:\");\n  Serial.println(level);\n  delay(200);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"gas1","type":"gas-sensor","x":330,"y":430},{"id":"bz1","type":"buzzer","x":330,"y":40}],"wires":[["gas1:AOUT","board:A0"],["gas1:DOUT","board:7"],["gas1:VCC","board:5V"],["gas1:GND","board:GND.3"],["bz1:2","board:8"],["bz1:1","board:GND.1"]]}},{"id":"heartbeat","name":"Heartbeat to Plotter","summary":"A pulse sensor on A0, sampled every 10 ms. Open the Plotter.","open":"https://lab.argynix.com/bench?example=heartbeat&run=1&view=3d","project":{"name":"Heartbeat to Plotter","ide":"arduino","board":"arduino-uno","code":"// A pulse sensor on A0, sampled every 10 ms: open the Plotter to watch the beat.\n// Set the heart rate in the inspector.\n\nvoid setup() {\n  Serial.begin(115200);\n}\n\nvoid loop() {\n  Serial.print(\"pulse:\");\n  Serial.println(analogRead(A0));\n  delay(10);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"hb1","type":"heart-beat-sensor","x":360,"y":440}],"wires":[["hb1:OUT","board:A0"],["hb1:VCC","board:5V"],["hb1:GND","board:GND.3"]]}},{"id":"tft-ili9341","name":"Colour TFT (ILI9341)","summary":"Adafruit_ILI9341 on the ESP32’s SPI: a title, a counter and a bar that grows.","open":"https://lab.argynix.com/bench?example=tft-ili9341&run=1&view=3d","project":{"name":"Colour TFT (ILI9341)","ide":"arduino","board":"esp32-devkit-v1","code":"// A 2.4-inch ILI9341 colour TFT on the ESP32's SPI bus (VSPI: SCK 18, MOSI 23,\n// MISO 19), drawn with Adafruit_GFX: text, rectangles, colours.\n#include <SPI.h>\n#include <Adafruit_GFX.h>\n#include <Adafruit_ILI9341.h>\n\n#define TFT_CS 5\n#define TFT_DC 4\n#define TFT_RST 15\n\nAdafruit_ILI9341 tft(TFT_CS, TFT_DC, TFT_RST);\nint count = 0;\n\nvoid setup() {\n  Serial.begin(115200);\n  tft.begin();\n  tft.setRotation(1);\n  tft.fillScreen(ILI9341_BLACK);\n  tft.fillRect(0, 0, 320, 40, ILI9341_NAVY);\n  tft.setTextColor(ILI9341_WHITE);\n  tft.setTextSize(2);\n  tft.setCursor(12, 12);\n  tft.print(\"Argynix Lab TFT\");\n  tft.drawRect(10, 180, 300, 30, ILI9341_WHITE);\n  Serial.println(\"Screen ready\");\n}\n\nvoid loop() {\n  tft.fillRect(10, 70, 300, 60, ILI9341_BLACK);\n  tft.setTextColor(ILI9341_YELLOW);\n  tft.setTextSize(5);\n  tft.setCursor(20, 80);\n  tft.print(count);\n  int width = map(count % 50, 0, 49, 0, 296);\n  tft.fillRect(12, 182, width, 26, count % 100 < 50 ? ILI9341_GREEN : ILI9341_ORANGE);\n  if (count % 50 == 49) tft.fillRect(12, 182, 296, 26, ILI9341_BLACK);\n  count++;\n  delay(100);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":60,"y":120},{"id":"tft1","type":"ili9341","x":300,"y":20}],"wires":[["tft1:SCK","board:D18"],["tft1:MOSI","board:D23"],["tft1:MISO","board:D19"],["tft1:CS","board:D5"],["tft1:D/C","board:D4"],["tft1:RST","board:D15"],["tft1:VCC","board:3V3"],["tft1:GND","board:GND.1"],["tft1:LED","board:3V3"]]}},{"id":"tft-round-gauge","name":"Round gauge (GC9A01)","summary":"A round 240x240 TFT on the ESP32-S3: a dial whose needle follows the knob.","open":"https://lab.argynix.com/bench?example=tft-round-gauge&run=1&view=3d","project":{"name":"Round gauge (GC9A01)","ide":"arduino","board":"esp32-s3-devkitc-1","code":"// A round GC9A01 TFT on the ESP32-S3's SPI (SCK 12, MOSI 11): a dial, and a needle\n// that follows the potentiometer on GPIO1. Turn the knob while it runs.\n#include <SPI.h>\n#include <Adafruit_GFX.h>\n#include <Adafruit_GC9A01A.h>\n\n#define TFT_CS 10\n#define TFT_DC 9\n#define TFT_RST 8\n\nAdafruit_GC9A01A tft(TFT_CS, TFT_DC, TFT_RST);\nconst int CX = 120, CY = 120;\nfloat last = -1;\n\nvoid needle(float value, uint16_t colour) {\n  float a = (value * 270.0 - 225.0) * DEG_TO_RAD;\n  tft.drawLine(CX, CY, CX + cos(a) * 88, CY + sin(a) * 88, colour);\n  tft.drawLine(CX + 1, CY, CX + 1 + cos(a) * 88, CY + sin(a) * 88, colour);\n}\n\nvoid setup() {\n  tft.begin();\n  tft.fillScreen(GC9A01A_BLACK);\n  for (int i = 0; i <= 10; i++) {\n    float a = (i * 27.0 - 225.0) * DEG_TO_RAD;\n    tft.drawLine(CX + cos(a) * 100, CY + sin(a) * 100, CX + cos(a) * 115, CY + sin(a) * 115, i > 7 ? GC9A01A_RED : GC9A01A_CYAN);\n  }\n  tft.setTextColor(GC9A01A_WHITE);\n  tft.setTextSize(2);\n  tft.setCursor(96, 170);\n  tft.print(\"LEVEL\");\n}\n\nvoid loop() {\n  float value = analogRead(1) / 4095.0;\n  if (fabs(value - last) > 0.01) {\n    if (last >= 0) needle(last, GC9A01A_BLACK);\n    needle(value, GC9A01A_ORANGE);\n    tft.fillCircle(CX, CY, 8, GC9A01A_WHITE);\n    tft.fillRect(90, 196, 70, 20, GC9A01A_BLACK);\n    tft.setCursor(98, 198);\n    tft.print(int(value * 100));\n    tft.print(\"%\");\n    last = value;\n  }\n  delay(30);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-s3-devkitc-1","x":60,"y":60},{"id":"tft1","type":"tft-gc9a01","x":300,"y":40},{"id":"pot1","type":"potentiometer","x":300,"y":300}],"wires":[["tft1:CLK","board:12"],["tft1:DIN","board:11"],["tft1:CS","board:10"],["tft1:DC","board:9"],["tft1:RST","board:8"],["tft1:VCC","board:3V3.1"],["tft1:GND","board:GND.1"],["pot1:SIG","board:1"],["pot1:VCC","board:3V3.2"],["pot1:GND","board:GND.2"]]}},{"id":"matrix-scroll","name":"Scrolling text (4 x MAX7219)","summary":"MD_MAX72XX scrolls a message across a 32x8 matrix, over hardware SPI.","open":"https://lab.argynix.com/bench?example=matrix-scroll&run=1&view=3d","project":{"name":"Scrolling text (4 x MAX7219)","ide":"arduino","board":"arduino-uno","code":"// Four MAX7219 matrices in a chain (an FC-16 module), on the Uno's SPI port\n// (DIN 11, CLK 13) with CS on 10. MD_MAX72XX's font, scrolled a column at a time.\n#include <MD_MAX72xx.h>\n#include <SPI.h>\n\nMD_MAX72XX mx(MD_MAX72XX::FC16_HW, 10, 4);\nconst char message[] = \"  HELLO FROM ARGYNIX LAB  \";\nuint8_t glyph[8];\nuint8_t glyphWidth = 0, glyphColumn = 0;\nconst char *next = message;\n\nvoid setup() {\n  mx.begin();\n  mx.control(MD_MAX72XX::INTENSITY, 4);\n  mx.clear();\n}\n\nvoid loop() {\n  if (glyphColumn >= glyphWidth) {\n    if (*next == 0) next = message;\n    glyphWidth = mx.getChar(*next++, sizeof(glyph), glyph) + 1;\n    glyph[glyphWidth - 1] = 0; // a blank column between letters\n    glyphColumn = 0;\n  }\n  mx.transform(MD_MAX72XX::TSL);\n  mx.setColumn(0, glyph[glyphColumn++]);\n  delay(40);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":220},{"id":"mtx1","type":"max7219-matrix-4","x":40,"y":40}],"wires":[["mtx1:DIN","board:11"],["mtx1:CLK","board:13"],["mtx1:CS","board:10"],["mtx1:VCC","board:5V"],["mtx1:GND","board:GND.1"]]}},{"id":"tm1637-clock","name":"Stopwatch (TM1637)","summary":"TM1637Display counts minutes and seconds, the colon blinking each second.","open":"https://lab.argynix.com/bench?example=tm1637-clock&run=1&view=3d","project":{"name":"Stopwatch (TM1637)","ide":"arduino","board":"arduino-uno","code":"// A TM1637 4-digit display on two pins (CLK 2, DIO 3): minutes and seconds since\n// the sketch started, the colon on for half of each second.\n#include <TM1637Display.h>\n\nTM1637Display display(2, 3);\n\nvoid setup() {\n  display.setBrightness(5);\n  display.clear();\n}\n\nvoid loop() {\n  unsigned long ms = millis();\n  int seconds = (ms / 1000) % 60;\n  int minutes = (ms / 60000) % 100;\n  bool colon = (ms % 1000) < 500;\n  display.showNumberDecEx(minutes * 100 + seconds, colon ? 0b01000000 : 0, true);\n  delay(50);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"disp1","type":"tm1637","x":380,"y":60}],"wires":[["disp1:CLK","board:2"],["disp1:DIO","board:3"],["disp1:VCC","board:5V"],["disp1:GND","board:GND.1"]]}},{"id":"cyd-dashboard","name":"Cheap Yellow Display dashboard","summary":"The CYD’s own 2.8\" screen on HSPI: a title bar, the uptime and a moving wave.","open":"https://lab.argynix.com/bench?example=cyd-dashboard&run=1&view=3d","project":{"name":"Cheap Yellow Display dashboard","ide":"arduino","board":"esp32-2432s028r","code":"// The Cheap Yellow Display (ESP32-2432S028R): its ILI9341 is on HSPI, with the pins the\n// board's Arduino variant names (CYD_TFT_SCK, CYD_TFT_DC...). The backlight is on CYD_TFT_BL.\n#include <SPI.h>\n#include <Adafruit_GFX.h>\n#include <Adafruit_ILI9341.h>\n\nSPIClass hspi(HSPI);\nAdafruit_ILI9341 tft(&hspi, CYD_TFT_DC, CYD_TFT_CS);\nint x = 0;\n\nvoid setup() {\n  pinMode(CYD_TFT_BL, OUTPUT);\n  digitalWrite(CYD_TFT_BL, HIGH);\n  hspi.begin(CYD_TFT_SCK, CYD_TFT_MISO, CYD_TFT_MOSI, CYD_TFT_CS);\n  tft.begin();\n  tft.setRotation(1);\n  tft.fillScreen(ILI9341_BLACK);\n  tft.fillRect(0, 0, 320, 30, ILI9341_DARKCYAN);\n  tft.setTextColor(ILI9341_WHITE);\n  tft.setTextSize(2);\n  tft.setCursor(8, 8);\n  tft.print(\"CYD dashboard\");\n}\n\nvoid loop() {\n  tft.fillRect(8, 44, 200, 24, ILI9341_BLACK);\n  tft.setCursor(8, 48);\n  tft.setTextColor(ILI9341_YELLOW);\n  tft.print(\"Up \");\n  tft.print(millis() / 1000);\n  tft.print(\" s\");\n  // A wave drawn a column at a time, the column ahead cleared.\n  int y = 160 + sin(x / 12.0) * 50;\n  tft.drawFastVLine((x + 1) % 320, 100, 120, ILI9341_BLACK);\n  tft.fillCircle(x, y, 2, ILI9341_GREEN);\n  x = (x + 1) % 320;\n  delay(20);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-2432s028r","x":60,"y":60}],"wires":[]}},{"id":"t-display-hello","name":"T-Display hello","summary":"LilyGo’s T-Display with Adafruit_ST7789: its 135x240 screen, a counter and colours.","open":"https://lab.argynix.com/bench?example=t-display-hello&run=1&view=3d","project":{"name":"T-Display hello","ide":"arduino","board":"lilygo-t-display","code":"// LilyGo's T-Display: an ST7789 135x240 on SPI pins of its own (SCK 18, MOSI 19, CS 5,\n// D/C 16, RST 23) and its backlight on 4. Adafruit_ST7789 drives it.\n#include <SPI.h>\n#include <Adafruit_GFX.h>\n#include <Adafruit_ST7789.h>\n\n#define TFT_CS 5\n#define TFT_DC 16\n#define TFT_RST 23\n#define TFT_BL 4\n\nAdafruit_ST7789 tft(TFT_CS, TFT_DC, TFT_RST);\nconst uint16_t colours[] = {ST77XX_RED, ST77XX_GREEN, ST77XX_BLUE, ST77XX_YELLOW, ST77XX_MAGENTA};\nint n = 0;\n\nvoid setup() {\n  pinMode(TFT_BL, OUTPUT);\n  digitalWrite(TFT_BL, HIGH);\n  SPI.begin(18, -1, 19, TFT_CS);\n  tft.init(135, 240);\n  tft.fillScreen(ST77XX_BLACK);\n  tft.fillRect(0, 0, 135, 40, ST77XX_BLUE);\n  tft.setTextColor(ST77XX_WHITE);\n  tft.setTextSize(2);\n  tft.setCursor(10, 12);\n  tft.print(\"T-Display\");\n}\n\nvoid loop() {\n  tft.fillRect(10, 60, 115, 40, ST77XX_BLACK);\n  tft.setCursor(10, 66);\n  tft.setTextSize(4);\n  tft.print(n);\n  tft.fillRect(10, 120, 115, 100, colours[n % 5]);\n  n++;\n  delay(500);\n}\n","files":[],"parts":[{"id":"board","type":"lilygo-t-display","x":80,"y":60}],"wires":[]}},{"id":"round-lcd-clock","name":"Round LCD clock (Waveshare)","summary":"The Waveshare ESP32-S3 round LCD: a watch face with a sweeping second hand.","open":"https://lab.argynix.com/bench?example=round-lcd-clock&run=1&view=3d","project":{"name":"Round LCD clock (Waveshare)","ide":"arduino","board":"waveshare-esp32s3-lcd-128","code":"// Waveshare's ESP32-S3 1.28-inch round LCD: a GC9A01 on the default SPI, its pins named by\n// the board's Arduino variant (LCD_DC, LCD_RST, LCD_BACKLIGHT). A watch face from millis().\n#include <SPI.h>\n#include <Adafruit_GFX.h>\n#include <Adafruit_GC9A01A.h>\n\nAdafruit_GC9A01A tft(SS, LCD_DC, LCD_RST);\nconst int C = 120;\nfloat last = -1;\n\nvoid hand(float turn, int length, uint16_t colour) {\n  float a = turn * TWO_PI - HALF_PI;\n  tft.drawLine(C, C, C + cos(a) * length, C + sin(a) * length, colour);\n}\n\nvoid setup() {\n  pinMode(LCD_BACKLIGHT, OUTPUT);\n  digitalWrite(LCD_BACKLIGHT, HIGH);\n  tft.begin();\n  tft.fillScreen(GC9A01A_BLACK);\n  tft.drawCircle(C, C, 118, GC9A01A_DARKGREY);\n  for (int i = 0; i < 12; i++) {\n    float a = i * TWO_PI / 12;\n    tft.fillCircle(C + cos(a) * 104, C + sin(a) * 104, i % 3 ? 2 : 4, GC9A01A_WHITE);\n  }\n}\n\nvoid loop() {\n  float s = (millis() % 60000) / 60000.0;\n  if (last >= 0) hand(last, 90, GC9A01A_BLACK);\n  hand(s, 90, GC9A01A_RED);\n  tft.fillCircle(C, C, 5, GC9A01A_WHITE);\n  last = s;\n  delay(100);\n}\n","files":[],"parts":[{"id":"board","type":"waveshare-esp32s3-lcd-128","x":80,"y":60}],"wires":[]}},{"id":"sd-logger","name":"Data logger (SD card)","summary":"The SD library writes the knob’s reading to LOG.CSV every half second; the inspector lists the file.","open":"https://lab.argynix.com/bench?example=sd-logger&run=1&view=3d","project":{"name":"Data logger (SD card)","ide":"arduino","board":"arduino-uno","code":"// A data logger: every half second, the time and the knob's reading go on a line of\n// LOG.CSV on the SD card. Select the card while it runs to see the file grow.\n#include <SPI.h>\n#include <SD.h>\n\nconst int CARD_CS = 10;\n\nvoid setup() {\n  Serial.begin(9600);\n  if (!SD.begin(CARD_CS)) {\n    Serial.println(\"No card found: check CS, SCK, DI and DO.\");\n    while (true) {\n    }\n  }\n  File log = SD.open(\"LOG.CSV\", FILE_WRITE);\n  log.println(\"ms,reading\");\n  log.close();\n  Serial.println(\"Logging to LOG.CSV\");\n}\n\nvoid loop() {\n  int reading = analogRead(A0);\n  File log = SD.open(\"LOG.CSV\", FILE_WRITE);\n  log.print(millis());\n  log.print(',');\n  log.println(reading);\n  log.close();\n  Serial.println(reading);\n  delay(500);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"sd1","type":"microsd-card","x":420,"y":60},{"id":"pot1","type":"potentiometer","x":420,"y":220}],"wires":[["sd1:SCK","board:13"],["sd1:DI","board:11"],["sd1:DO","board:12"],["sd1:CS","board:10"],["sd1:VCC","board:5V"],["sd1:GND","board:GND.1"],["pot1:SIG","board:A0"],["pot1:VCC","board:5V"],["pot1:GND","board:GND.2"]]}},{"id":"rfid-door","name":"RFID door (RC522)","summary":"The MFRC522 library reads a card’s UID: the known card lights green, any other red. Click the reader to hold a card to it.","open":"https://lab.argynix.com/bench?example=rfid-door&run=1&view=3d","project":{"name":"RFID door (RC522)","ide":"arduino","board":"arduino-uno","code":"// An RFID door: the RC522 reads the UID of the card held to it. The known card\n// (DE AD BE EF) lights the green LED, any other the red one. Click the reader while it\n// runs to hold the card to it; change the card's UID in the inspector.\n#include <SPI.h>\n#include <MFRC522.h>\n\nMFRC522 rfid(10, 9);  // SDA (chip select), RST\nconst byte KNOWN[4] = {0xDE, 0xAD, 0xBE, 0xEF};\nconst int GREEN = 6, RED = 7;\n\nvoid setup() {\n  Serial.begin(9600);\n  pinMode(GREEN, OUTPUT);\n  pinMode(RED, OUTPUT);\n  SPI.begin();\n  rfid.PCD_Init();\n  Serial.println(\"Hold a card to the reader\");\n}\n\nvoid loop() {\n  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;\n  bool known = rfid.uid.size == 4 && memcmp(rfid.uid.uidByte, KNOWN, 4) == 0;\n  Serial.print(\"Card \");\n  for (byte i = 0; i < rfid.uid.size; i++) {\n    if (rfid.uid.uidByte[i] < 0x10) Serial.print('0');\n    Serial.print(rfid.uid.uidByte[i], HEX);\n    Serial.print(' ');\n  }\n  Serial.println(known ? \": welcome\" : \": not known\");\n  digitalWrite(known ? GREEN : RED, HIGH);\n  delay(1500);\n  digitalWrite(GREEN, LOW);\n  digitalWrite(RED, LOW);\n  rfid.PICC_HaltA();\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":220},{"id":"rfid1","type":"rc522","attrs":{"uid":"DE AD BE EF"},"x":420,"y":40},{"id":"led1","type":"led","attrs":{"color":"green"},"x":420,"y":200},{"id":"led2","type":"led","attrs":{"color":"red"},"x":480,"y":200}],"wires":[["rfid1:SCK","board:13"],["rfid1:MOSI","board:11"],["rfid1:MISO","board:12"],["rfid1:SDA","board:10"],["rfid1:RST","board:9"],["rfid1:3.3V","board:3.3V"],["rfid1:GND","board:GND.1"],["led1:A","board:6"],["led1:C","board:GND.2"],["led2:A","board:7"],["led2:C","board:GND.3"]]}},{"id":"epaper-badge","name":"Name badge (e-paper)","summary":"GxEPD2 draws a badge on a 1.54\" e-paper, then sleeps: the picture stays.","open":"https://lab.argynix.com/bench?example=epaper-badge&run=1&view=3d","project":{"name":"Name badge (e-paper)","ide":"arduino","board":"esp32-s3-devkitc-1","code":"// A name badge on a 1.54-inch e-paper (SSD1681), drawn once with GxEPD2. The panel\n// takes a few seconds to refresh (BUSY is HIGH meanwhile) and keeps the picture after.\n#include <GxEPD2_BW.h>\n#include <Fonts/FreeSansBold12pt7b.h>\n\nGxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(10, 9, 8, 7));  // CS, DC, RST, BUSY\n\nvoid setup() {\n  Serial.begin(115200);\n  display.init(115200);\n  display.setRotation(0);\n  display.setFont(&FreeSansBold12pt7b);\n  display.setTextColor(GxEPD_BLACK);\n  display.setFullWindow();\n  display.firstPage();\n  do {\n    display.fillScreen(GxEPD_WHITE);\n    display.fillRect(0, 0, 200, 48, GxEPD_BLACK);\n    display.setTextColor(GxEPD_WHITE);\n    display.setCursor(14, 32);\n    display.print(\"HELLO, I AM\");\n    display.setTextColor(GxEPD_BLACK);\n    display.setCursor(30, 112);\n    display.print(\"ARGYNIX\");\n    display.drawRect(8, 140, 184, 44, GxEPD_BLACK);\n    display.setCursor(48, 170);\n    display.print(\"Lab maker\");\n  } while (display.nextPage());\n  display.hibernate();\n  Serial.println(\"Badge drawn\");\n}\n\nvoid loop() {}\n","files":[],"parts":[{"id":"board","type":"esp32-s3-devkitc-1","x":60,"y":60},{"id":"epd1","type":"epaper-154","x":320,"y":60}],"wires":[["epd1:CLK","board:12"],["epd1:DIN","board:11"],["epd1:CS","board:10"],["epd1:DC","board:9"],["epd1:RST","board:8"],["epd1:BUSY","board:7"],["epd1:VCC","board:3V3.1"],["epd1:GND","board:GND.1"]]}},{"id":"web-hotspot-led","name":"Web switch on a hotspot","summary":"The ESP32 starts its own Wi-Fi (softAP) and serves a page with ON and OFF buttons for an LED. Join it from the phone.","open":"https://lab.argynix.com/bench?example=web-hotspot-led&run=1&view=3d","project":{"name":"Web switch on a hotspot","ide":"arduino","board":"esp32-devkit-v1","code":"// The ESP32 starts its own Wi-Fi, \"ESP32-Lab\" (password labpass123), and serves a page\n// at 192.168.4.1 with buttons for the LED on GPIO 2. Run it, open the phone at the\n// bench's foot, join ESP32-Lab in Wi-Fi, then open 192.168.4.1 in its browser.\n#include <WiFi.h>\n#include <WebServer.h>\n\nconst int LED = 2;\nWebServer server(80);\nbool on = false;\n\nString page() {\n  String html = \"<!doctype html><html><head><meta name=viewport content='width=device-width'>\"\n                \"<style>body{font-family:sans-serif;text-align:center;padding:24px;background:#10151c;color:#eef}\"\n                \"a{display:inline-block;margin:8px;padding:14px 28px;border-radius:10px;color:#fff;text-decoration:none}\"\n                \".on{background:#2e9e6a}.off{background:#c8372d}</style></head><body>\";\n  html += \"<h2>ESP32 web switch</h2><p>The LED is <b>\";\n  html += on ? \"ON\" : \"OFF\";\n  html += \"</b></p><a class=on href='/on'>ON</a><a class=off href='/off'>OFF</a></body></html>\";\n  return html;\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(LED, OUTPUT);\n  WiFi.softAP(\"ESP32-Lab\", \"labpass123\");\n  Serial.print(\"Hotspot up. Open http://\");\n  Serial.println(WiFi.softAPIP());\n  server.on(\"/\", []() { server.send(200, \"text/html\", page()); });\n  server.on(\"/on\", []() {\n    on = true;\n    digitalWrite(LED, HIGH);\n    server.sendHeader(\"Location\", \"/\");\n    server.send(303);\n  });\n  server.on(\"/off\", []() {\n    on = false;\n    digitalWrite(LED, LOW);\n    server.sendHeader(\"Location\", \"/\");\n    server.send(303);\n  });\n  server.begin();\n}\n\nvoid loop() {\n  server.handleClient();\n  delay(2);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":80,"y":120},{"id":"led1","type":"led","attrs":{"color":"green"},"x":300,"y":120},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":300,"y":220}],"wires":[["board:D2","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"]]}},{"id":"web-live-sensor","name":"Live sensor page","summary":"ESPAsyncWebServer on the Lab’s network: weather.local shows the knob’s reading, fetched every second by the page.","open":"https://lab.argynix.com/bench?example=web-live-sensor&run=1&view=3d","project":{"name":"Live sensor page","ide":"arduino","board":"esp32-devkit-v1","code":"// On the Lab's network (ARGYNIX-Lab), ESPAsyncWebServer serves a page at weather.local\n// (10.42.0.17) that asks /reading every second. Run it, join ARGYNIX-Lab on the phone,\n// open weather.local, then turn the knob.\n#include <WiFi.h>\n#include <AsyncTCP.h>\n#include <ESPAsyncWebServer.h>\n#include <ESPmDNS.h>\n\nAsyncWebServer server(80);\n\nconst char page[] PROGMEM = R\"html(<!doctype html><html><head>\n<meta name=viewport content=\"width=device-width\">\n<style>body{font-family:sans-serif;text-align:center;padding:24px;background:#0f1e31;color:#eef}\n#v{font-size:48px;font-weight:700;color:#7fd3ff}</style></head><body>\n<h2>%TITLE%</h2><div id=v>...</div><p>of 4095, every second</p>\n<script>\nsetInterval(() => fetch('/reading').then((r) => r.text()).then((t) => (document.getElementById('v').textContent = t)), 1000);\n</script></body></html>)html\";\n\nString processor(const String &name) { return name == \"TITLE\" ? String(\"Knob on GPIO 34\") : String(); }\n\nvoid setup() {\n  Serial.begin(115200);\n  WiFi.begin(\"ARGYNIX-Lab\", \"\");\n  while (WiFi.status() != WL_CONNECTED) delay(100);\n  MDNS.begin(\"weather\");\n  Serial.print(\"Open http://weather.local or http://\");\n  Serial.println(WiFi.localIP());\n  server.on(\"/\", HTTP_GET, [](AsyncWebServerRequest *request) { request->send_P(200, \"text/html\", page, processor); });\n  server.on(\"/reading\", HTTP_GET, [](AsyncWebServerRequest *request) { request->send(200, \"text/plain\", String(analogRead(34))); });\n  server.begin();\n}\n\nvoid loop() { delay(1000); }\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":80,"y":120},{"id":"pot1","type":"potentiometer","x":300,"y":160}],"wires":[["pot1:SIG","board:D34"],["pot1:VCC","board:3V3"],["pot1:GND","board:GND.1"]]}},{"id":"gsm-sms-led","name":"SMS switch (SIM800L)","summary":"Text \"LED ON\" or \"LED OFF\" to the SIM800L and pin 13 follows; the board texts back what it did.","open":"https://lab.argynix.com/bench?example=gsm-sms-led&run=1&view=3d","project":{"name":"SMS switch (SIM800L)","ide":"arduino","board":"arduino-uno","code":"// An LED switched by SMS: a SIM800L on SoftwareSerial (pins 7 and 8). Send it \"LED ON\"\n// or \"LED OFF\" from the modem's settings in the inspector; the board answers by SMS.\n#include <SoftwareSerial.h>\n\nSoftwareSerial gsm(7, 8); // RX (from the module's TXD), TX (to its RXD)\nconst char *OWNER = \"+919876543210\";\n\nString readLine(uint32_t ms) {\n  String s;\n  uint32_t t = millis();\n  while (millis() - t < ms) {\n    while (gsm.available()) {\n      char c = gsm.read();\n      if (c == '\\n') return s;\n      if (c != '\\r') s += c;\n    }\n  }\n  return s;\n}\n\nvoid command(const char *at, uint32_t wait = 500) {\n  gsm.println(at);\n  uint32_t t = millis();\n  while (millis() - t < wait) while (gsm.available()) Serial.write(gsm.read());\n}\n\nvoid sms(const char *to, const char *text) {\n  gsm.print(\"AT+CMGS=\\\"\");\n  gsm.print(to);\n  gsm.println(\"\\\"\");\n  delay(300);\n  gsm.print(text);\n  gsm.write(26); // Ctrl-Z sends it\n  delay(1500);\n  while (gsm.available()) Serial.write(gsm.read());\n}\n\nvoid setup() {\n  pinMode(13, OUTPUT);\n  Serial.begin(9600);\n  gsm.begin(9600);\n  delay(3000);\n  for (int i = 0; i < 3; i++) command(\"AT\", 300); // it learns 9600 baud from \"AT\"\n  command(\"ATE0\");\n  command(\"AT+CMGF=1\");          // text mode\n  command(\"AT+CNMI=2,1,0,0,0\");  // tell us when an SMS arrives\n  Serial.println(\"Ready: send it LED ON or LED OFF\");\n}\n\nvoid loop() {\n  String line = readLine(100);\n  if (!line.startsWith(\"+CMTI:\")) return;\n  int index = line.substring(line.indexOf(',') + 1).toInt();\n  gsm.print(\"AT+CMGR=\");\n  gsm.println(index);\n  // The answer: a blank line, +CMGR: \"REC UNREAD\",\"+91…\", then the text.\n  String head;\n  uint32_t t = millis();\n  while (!head.startsWith(\"+CMGR:\") && millis() - t < 2000) head = readLine(500);\n  String text = readLine(500);\n  Serial.print(\"SMS: \");\n  Serial.println(text);\n  if (text.indexOf(\"ON\") >= 0) {\n    digitalWrite(13, HIGH);\n    sms(OWNER, \"LED is ON\");\n  } else if (text.indexOf(\"OFF\") >= 0) {\n    digitalWrite(13, LOW);\n    sms(OWNER, \"LED is OFF\");\n  }\n  command(\"AT+CMGD=1,4\");        // clear the inbox\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"gsm","type":"sim800l","attrs":{"sim":"in","network":"on","callee":"answers","number":"+910000000001","gnss":"no","sky":"open"},"x":420,"y":40}],"wires":[["gsm:RXD","board:8"],["gsm:TXD","board:7"],["gsm:VCC","board:5V"],["gsm:GND","board:GND.1"]]}},{"id":"lte-http-a7670c","name":"4G HTTP with AT commands (A7670C)","summary":"An ESP32 brings up 4G data on an A7670C and fetches a page with the module's own HTTP commands.","open":"https://lab.argynix.com/bench?example=lte-http-a7670c&run=1&view=3d","project":{"name":"4G HTTP with AT commands (A7670C)","ide":"arduino","board":"esp32-devkit-v1","code":"// An ESP32 on 4G through SIMCom's A7670C, with plain AT commands on Serial2 (RX2 16,\n// TX2 17): the SIM, registration, data, then an HTTP GET with AT+HTTP… every 20 s.\n#define AT Serial2\n\nString ask(const char *cmd, uint32_t ms = 1000) {\n  AT.print(cmd);\n  AT.print(\"\\r\");\n  String got;\n  uint32_t t = millis();\n  while (millis() - t < ms) while (AT.available()) got += (char)AT.read();\n  got.trim();\n  Serial.print(\"> \");\n  Serial.println(cmd);\n  Serial.println(got);\n  return got;\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  AT.begin(115200, SERIAL_8N1, 16, 17);\n  delay(3000);\n  ask(\"ATE0\");\n  ask(\"AT+CPIN?\");\n  ask(\"AT+CSQ\");\n  while (ask(\"AT+CREG?\").indexOf(\",1\") < 0) delay(1000);\n  ask(\"AT+CGDCONT=1,\\\"IP\\\",\\\"internet\\\"\");\n  ask(\"AT+NETOPEN\", 2000);\n}\n\nvoid loop() {\n  ask(\"AT+HTTPINIT\");\n  ask(\"AT+HTTPPARA=\\\"URL\\\",\\\"http://example.com/time\\\"\");\n  ask(\"AT+HTTPACTION=0\", 3000);\n  ask(\"AT+HTTPREAD=0,500\", 1500);\n  ask(\"AT+HTTPTERM\");\n  delay(20000);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":60,"y":120},{"id":"lte","type":"a7670c","attrs":{"sim":"in","network":"on","callee":"answers","number":"+910000000001","gnss":"no","sky":"open"},"x":380,"y":40}],"wires":[["lte:RXD","board:TX2"],["lte:TXD","board:RX2"],["lte:VCC","board:VIN"],["lte:GND","board:GND.1"]]}},{"id":"lte-tinygsm-sim7600","name":"TinyGSM web client (SIM7600G-H)","summary":"TinyGSM and ArduinoHttpClient on an ESP32 with a SIM7600G-H: registered, data up, a JSON page fetched.","open":"https://lab.argynix.com/bench?example=lte-tinygsm-sim7600&run=1&view=3d","project":{"name":"TinyGSM web client (SIM7600G-H)","ide":"arduino","board":"esp32-devkit-v1","code":"// TinyGSM on an ESP32 with a SIM7600G-H on Serial2: it registers, brings data up and\n// fetches http://example.com/json with ArduinoHttpClient every 30 s.\n#define TINY_GSM_MODEM_SIM7600\n#define TINY_GSM_RX_BUFFER 1024\n#include <TinyGsmClient.h>\n#include <ArduinoHttpClient.h>\n\n#define SerialAT Serial2\nconst char apn[] = \"internet\";\n\nTinyGsm modem(SerialAT);\nTinyGsmClient client(modem);\nHttpClient http(client, \"example.com\", 80);\n\nvoid setup() {\n  Serial.begin(115200);\n  SerialAT.begin(115200, SERIAL_8N1, 16, 17);\n  delay(3000);\n  Serial.println(\"Starting the modem...\");\n  modem.init();\n  Serial.print(\"Modem: \");\n  Serial.println(modem.getModemInfo());\n  Serial.print(\"Waiting for the network...\");\n  if (!modem.waitForNetwork()) {\n    Serial.println(\" none\");\n    return;\n  }\n  Serial.println(\" registered\");\n  Serial.print(\"Signal: \");\n  Serial.println(modem.getSignalQuality());\n  if (!modem.gprsConnect(apn)) {\n    Serial.println(\"Data: failed\");\n    return;\n  }\n  Serial.print(\"Data up, IP \");\n  Serial.println(modem.localIP());\n}\n\nvoid loop() {\n  int err = http.get(\"/json\");\n  if (err == 0) {\n    Serial.print(\"Status: \");\n    Serial.println(http.responseStatusCode());\n    Serial.println(http.responseBody());\n  } else {\n    Serial.print(\"HTTP error \");\n    Serial.println(err);\n  }\n  http.stop();\n  delay(30000);\n}\n","files":[{"name":"libraries.txt","code":"TinyGSM\nArduinoHttpClient\n"}],"parts":[{"id":"board","type":"esp32-devkit-v1","x":60,"y":120},{"id":"lte","type":"sim7600","attrs":{"sim":"in","network":"on","callee":"answers","number":"+910000000001","gnss":"yes","sky":"open"},"x":380,"y":30}],"wires":[["lte:RXD","board:TX2"],["lte:TXD","board:RX2"],["lte:VCC","board:VIN"],["lte:GND","board:GND.1"]]}},{"id":"lte-mqtt-ec200u","name":"4G MQTT (EC200U)","summary":"Quectel EC200U on an ESP32: data up, then the module's own MQTT commands publish a reading and listen for commands.","open":"https://lab.argynix.com/bench?example=lte-mqtt-ec200u&run=1&view=3d","project":{"name":"4G MQTT (EC200U)","ide":"arduino","board":"esp32-devkit-v1","code":"// MQTT over 4G with Quectel's EC200U: AT+QICSGP and AT+QIACT bring data up, then\n// AT+QMTOPEN, AT+QMTCONN, AT+QMTSUB and AT+QMTPUB talk to the Lab's MQTT broker.\n// Every 5 s it publishes the knob on GPIO 34 to lab/ec200u/knob, and prints what\n// arrives on lab/ec200u/cmd.\n#define AT Serial2\n\nString ask(const char *cmd, uint32_t ms = 800) {\n  AT.print(cmd);\n  AT.print(\"\\r\");\n  String got;\n  uint32_t t = millis();\n  while (millis() - t < ms) while (AT.available()) got += (char)AT.read();\n  got.trim();\n  Serial.println(got);\n  return got;\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  AT.begin(115200, SERIAL_8N1, 16, 17);\n  delay(3000);\n  ask(\"ATE0\");\n  while (ask(\"AT+CREG?\").indexOf(\",1\") < 0) delay(1000);\n  ask(\"AT+QICSGP=1,1,\\\"internet\\\",\\\"\\\",\\\"\\\",1\");\n  ask(\"AT+QIACT=1\", 1500);\n  ask(\"AT+QMTOPEN=0,\\\"broker.lab\\\",1883\", 1500);\n  ask(\"AT+QMTCONN=0,\\\"esp32-ec200u\\\"\", 1500);\n  ask(\"AT+QMTSUB=0,1,\\\"lab/ec200u/cmd\\\",0\", 1000);\n}\n\nvoid loop() {\n  int knob = analogRead(34);\n  char cmd[80];\n  snprintf(cmd, sizeof cmd, \"AT+QMTPUB=0,0,0,0,\\\"lab/ec200u/knob\\\",\\\"%d\\\"\", knob);\n  ask(cmd, 600);\n  uint32_t t = millis();\n  while (millis() - t < 5000) while (AT.available()) Serial.write(AT.read());\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":60,"y":140},{"id":"lte","type":"ec200u","attrs":{"sim":"in","network":"on","callee":"answers","number":"+910000000001","gnss":"yes","sky":"open"},"x":380,"y":20},{"id":"pot1","type":"potentiometer","x":400,"y":260}],"wires":[["lte:RXD","board:TX2"],["lte:TXD","board:RX2"],["lte:VCC","board:VIN"],["lte:GND","board:GND.1"],["pot1:SIG","board:D34"],["pot1:VCC","board:3V3"],["pot1:GND","board:GND.2"]]}},{"id":"gps-tinygps","name":"GPS position (NEO-6M)","summary":"TinyGPS++ reads a NEO-6M on SoftwareSerial: latitude, longitude, altitude, satellites, time. Move it in the inspector.","open":"https://lab.argynix.com/bench?example=gps-tinygps&run=1&view=3d","project":{"name":"GPS position (NEO-6M)","ide":"arduino","board":"arduino-uno","code":"// A NEO-6M GPS on SoftwareSerial (pins 4 and 3) at 9600 baud, read with TinyGPS++.\n// Set its position, altitude and speed in the inspector; it has a fix a few seconds in.\n#include <SoftwareSerial.h>\n#include <TinyGPSPlus.h>\n\nSoftwareSerial gpsSerial(4, 3); // RX (from the GPS's TX), TX (to its RX)\nTinyGPSPlus gps;\nuint32_t last = 0;\n\nvoid setup() {\n  Serial.begin(115200);\n  gpsSerial.begin(9600);\n  Serial.println(\"Waiting for a fix...\");\n}\n\nvoid loop() {\n  while (gpsSerial.available()) gps.encode(gpsSerial.read());\n  if (millis() - last < 2000) return;\n  last = millis();\n  if (!gps.location.isValid()) {\n    Serial.println(\"No fix yet\");\n    return;\n  }\n  Serial.print(\"Lat \");\n  Serial.print(gps.location.lat(), 6);\n  Serial.print(\"  Lon \");\n  Serial.print(gps.location.lng(), 6);\n  Serial.print(\"  Alt \");\n  Serial.print(gps.altitude.meters());\n  Serial.print(\" m  Sats \");\n  Serial.print(gps.satellites.value());\n  Serial.print(\"  \");\n  Serial.print(gps.time.hour());\n  Serial.print(':');\n  Serial.print(gps.time.minute());\n  Serial.print(':');\n  Serial.println(gps.time.second());\n}\n","files":[{"name":"libraries.txt","code":"TinyGPSPlus\n"}],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"gps","type":"neo6m","attrs":{"sky":"open","baud":"9600"},"x":420,"y":60}],"wires":[["gps:RX","board:3"],["gps:TX","board:4"],["gps:VCC","board:5V"],["gps:GND","board:GND.1"]]}},{"id":"ir-remote-leds","name":"IR remote and three LEDs","summary":"IRremote decodes the remote: keys 1, 2 and 3 toggle three LEDs, and every code is printed.","open":"https://lab.argynix.com/bench?example=ir-remote-leds&run=1&view=3d","project":{"name":"IR remote and three LEDs","ide":"arduino","board":"arduino-uno","code":"// An IR receiver on pin 2 and the 20-key remote: IRremote decodes NEC. Keys 1, 2, 3\n// toggle the LEDs on 9, 10, 11; power turns them all off. Press the remote's keys on\n// the bench (or in the inspector).\n#include <IRremote.hpp>\n\nconst int LEDS[] = {9, 10, 11};\nbool on[3];\n\nvoid setup() {\n  Serial.begin(115200);\n  for (int pin : LEDS) pinMode(pin, OUTPUT);\n  IrReceiver.begin(2);\n  Serial.println(\"Press a key on the remote\");\n}\n\nvoid loop() {\n  if (!IrReceiver.decode()) return;\n  uint16_t cmd = IrReceiver.decodedIRData.command;\n  bool repeat = IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT;\n  IrReceiver.resume();\n  if (repeat) return;\n  Serial.print(\"Key code \");\n  Serial.println(cmd);\n  int which = cmd == 48 ? 0 : cmd == 24 ? 1 : cmd == 122 ? 2 : -1; // keys 1, 2, 3\n  if (which >= 0) {\n    on[which] = !on[which];\n    digitalWrite(LEDS[which], on[which]);\n  } else if (cmd == 162) {                                         // power\n    for (int i = 0; i < 3; i++) digitalWrite(LEDS[i], on[i] = false);\n  }\n}\n","files":[{"name":"libraries.txt","code":"IRremote\n"}],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"ir","type":"ir-receiver","x":420,"y":60},{"id":"remote","type":"ir-remote","x":560,"y":20},{"id":"led1","type":"led","attrs":{"color":"red"},"x":250,"y":40},{"id":"led2","type":"led","attrs":{"color":"green"},"x":290,"y":40},{"id":"led3","type":"led","attrs":{"color":"blue"},"x":330,"y":40}],"wires":[["ir:DAT","board:2"],["ir:VCC","board:5V"],["ir:GND","board:GND.1"],["led1:A","board:9"],["led2:A","board:10"],["led3:A","board:11"],["led1:C","board:GND.2"],["led2:C","board:GND.2"],["led3:C","board:GND.2"]]}},{"id":"rf-keyfob-relay","name":"433 MHz key fob and a relay","summary":"RCSwitch reads a 433 MHz key fob: key A switches the relay on, key B off.","open":"https://lab.argynix.com/bench?example=rf-keyfob-relay&run=1&view=3d","project":{"name":"433 MHz key fob and a relay","ide":"arduino","board":"arduino-uno","code":"// A 433 MHz receiver on pin 2 (interrupt 0) and a four-key fob: RCSwitch decodes its\n// EV1527 codes. Key A switches the relay on pin 7 on, key B off. Every code is printed:\n// set the fob's address in the inspector and the codes change with it.\n#include <RCSwitch.h>\n\nRCSwitch rf;\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(7, OUTPUT);\n  rf.enableReceive(0); // pin 2\n  Serial.println(\"Press A or B on the key fob\");\n}\n\nvoid loop() {\n  if (!rf.available()) return;\n  unsigned long code = rf.getReceivedValue();\n  Serial.print(\"Code \");\n  Serial.print(code);\n  Serial.print(\" (\");\n  Serial.print(rf.getReceivedBitlength());\n  Serial.println(\" bits)\");\n  switch (code & 0xF) {     // the fob's key is in the last four bits\n    case 8: digitalWrite(7, HIGH); Serial.println(\"Relay on\"); break;  // A\n    case 4: digitalWrite(7, LOW); Serial.println(\"Relay off\"); break;  // B\n  }\n  rf.resetAvailable();\n}\n","files":[{"name":"libraries.txt","code":"rc-switch\n"}],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"rx","type":"rf-receiver","x":420,"y":60},{"id":"fob","type":"rf-remote","attrs":{"address":"5a3c1"},"x":600,"y":20},{"id":"relay","type":"relay-module","x":400,"y":260}],"wires":[["rx:DATA","board:2"],["rx:VCC","board:5V"],["rx:GND","board:GND.1"],["relay:IN","board:7"],["relay:VCC","board:5V"],["relay:GND","board:GND.2"]]}},{"id":"lora-ping","name":"LoRa ping (RFM95W)","summary":"The LoRa library on an RFM95W at 868 MHz: a numbered ping every five seconds, and the other radio's answers with their RSSI.","open":"https://lab.argynix.com/bench?example=lora-ping&run=1&view=3d","project":{"name":"LoRa ping (RFM95W)","ide":"arduino","board":"arduino-uno","code":"// LoRa with Sandeep Mistry's library on an RFM95W (SX1276) at 868 MHz: NSS on 10,\n// RESET on 9, DIO0 on 2. It sends \"ping n\" every 5 s and prints what comes back. The\n// radio at the other end is the part's setting: one that answers, one that sends, none.\n#include <SPI.h>\n#include <LoRa.h>\n\nint n = 0;\nuint32_t last = 0;\n\nvoid setup() {\n  Serial.begin(115200);\n  LoRa.setPins(10, 9, 2);\n  if (!LoRa.begin(868E6)) {\n    Serial.println(\"LoRa: no radio\");\n    while (true);\n  }\n  LoRa.setSpreadingFactor(7);\n  Serial.println(\"LoRa ready at 868 MHz, SF7\");\n}\n\nvoid loop() {\n  if (millis() - last > 5000) {\n    last = millis();\n    LoRa.beginPacket();\n    LoRa.print(\"ping \");\n    LoRa.print(n++);\n    LoRa.endPacket();\n    Serial.print(\"Sent ping \");\n    Serial.println(n - 1);\n  }\n  int size = LoRa.parsePacket();\n  if (size) {\n    Serial.print(\"Got \\\"\");\n    while (LoRa.available()) Serial.write(LoRa.read());\n    Serial.print(\"\\\" RSSI \");\n    Serial.print(LoRa.packetRssi());\n    Serial.print(\" dBm, SNR \");\n    Serial.println(LoRa.packetSnr());\n  }\n}\n","files":[{"name":"libraries.txt","code":"LoRa\n"}],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"lora","type":"rfm95w","attrs":{"peer":"answers"},"x":420,"y":40}],"wires":[["lora:SCK","board:13"],["lora:MISO","board:12"],["lora:MOSI","board:11"],["lora:NSS","board:10"],["lora:RST","board:9"],["lora:DIO0","board:2"],["lora:3.3V","board:3.3V"],["lora:GND","board:GND.1"]]}},{"id":"ethernet-web-server","name":"Ethernet web server (W5500)","summary":"A W5500 on an Uno: an address by DHCP, then a page with the knob's reading. Open it on the bench's phone.","open":"https://lab.argynix.com/bench?example=ethernet-web-server&run=1&view=3d","project":{"name":"Ethernet web server (W5500)","ide":"arduino","board":"arduino-uno","code":"// A web server on Ethernet: a W5500 on SPI (CS on 10). DHCP gives it an address on the\n// Lab's network; its page shows the knob on A0 and refreshes itself. Open the phone at\n// the bench's foot to see it.\n#include <SPI.h>\n#include <Ethernet.h>\n\nbyte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};\nEthernetServer server(80);\n\nvoid setup() {\n  Serial.begin(115200);\n  Ethernet.init(10);\n  if (Ethernet.begin(mac) == 0) {\n    Serial.println(\"DHCP failed: is the cable in?\");\n    while (true);\n  }\n  server.begin();\n  Serial.print(\"Web server at http://\");\n  Serial.println(Ethernet.localIP());\n}\n\nvoid loop() {\n  EthernetClient client = server.available();\n  if (!client) return;\n  bool blank = true;\n  while (client.connected()) {\n    if (!client.available()) continue;\n    char c = client.read();\n    if (c == '\\n' && blank) {\n      client.println(\"HTTP/1.1 200 OK\");\n      client.println(\"Content-Type: text/html\");\n      client.println(\"Connection: close\");\n      client.println();\n      client.print(\"<!DOCTYPE html><html><head><meta http-equiv='refresh' content='2'>\");\n      client.print(\"<title>W5500</title></head><body style='font-family:sans-serif'>\");\n      client.print(\"<h1>Knob: \");\n      client.print(analogRead(A0));\n      client.println(\"</h1><p>Served by a W5500 on the Argynix Lab network.</p></body></html>\");\n      break;\n    }\n    if (c == '\\n') blank = true;\n    else if (c != '\\r') blank = false;\n  }\n  delay(1);\n  client.stop();\n  Serial.println(\"Page served\");\n}\n","files":[{"name":"libraries.txt","code":"Ethernet\n"}],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"eth","type":"w5500","attrs":{"cable":"in"},"x":400,"y":40},{"id":"pot1","type":"potentiometer","x":420,"y":260}],"wires":[["eth:SCK","board:13"],["eth:MISO","board:12"],["eth:MOSI","board:11"],["eth:CS","board:10"],["eth:3.3V","board:3.3V"],["eth:GND","board:GND.1"],["pot1:SIG","board:A0"],["pot1:VCC","board:5V"],["pot1:GND","board:GND.2"]]}},{"id":"esp32-bluetooth-led","name":"Bluetooth LED switch (ESP32)","summary":"Pair the phone with ESP32_LED (its Bluetooth app) and send 1 or 0: the LED follows and the board answers.","open":"https://lab.argynix.com/bench?example=esp32-bluetooth-led&run=1&view=3d","project":{"name":"Bluetooth LED switch (ESP32)","ide":"arduino","board":"esp32-devkit-v1","code":"// An LED switched from a phone over Bluetooth (Classic, serial). Open the phone at the\n// bench's foot, its Bluetooth app, connect to ESP32_LED and send 1 or 0.\n#include \"BluetoothSerial.h\"\n\nBluetoothSerial SerialBT;\nconst int LED = 2;\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(LED, OUTPUT);\n  SerialBT.begin(\"ESP32_LED\");\n  Serial.println(\"Bluetooth up: connect to ESP32_LED\");\n}\n\nvoid loop() {\n  if (SerialBT.available()) {\n    char c = SerialBT.read();\n    if (c == '1') {\n      digitalWrite(LED, HIGH);\n      SerialBT.println(\"LED on\");\n      Serial.println(\"The phone turned the LED on\");\n    } else if (c == '0') {\n      digitalWrite(LED, LOW);\n      SerialBT.println(\"LED off\");\n      Serial.println(\"The phone turned the LED off\");\n    }\n  }\n  delay(10);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":60,"y":120},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":330,"y":90},{"id":"led1","type":"led","attrs":{"color":"blue"},"x":420,"y":60}],"wires":[["board:D2","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.1"]]}},{"id":"esp32-ble-thermometer","name":"BLE thermometer (ESP32)","summary":"A BLE server: the DHT22’s temperature as a characteristic the phone reads and follows, and a second one it writes \"on\" or \"off\" to for the LED.","open":"https://lab.argynix.com/bench?example=esp32-ble-thermometer&run=1&view=3d","project":{"name":"BLE thermometer (ESP32)","ide":"arduino","board":"esp32-devkit-v1","code":"// A Bluetooth LE thermometer: the DHT22's temperature in a characteristic the phone\n// follows (it notifies every two seconds while connected), and a second one the phone\n// writes \"on\" or \"off\" to for the LED. Phone: Bluetooth app, connect to \"ESP32 Thermo\".\n#include <BLEDevice.h>\n#include <BLEServer.h>\n#include <BLE2902.h>\n#include <DHT.h>\n\n#define SERVICE_UUID \"4fafc201-1fb5-459e-8fcc-c5c9c331914b\"\n#define TEMP_UUID    \"beb5483e-36e1-4688-b7f5-ea07361b26a8\"\n#define LED_UUID     \"e3223119-9445-4e96-a4a1-85358c4046a2\"\n\nDHT dht(4, DHT22);\nBLEServer *server;\nBLECharacteristic *temperature;\nbool connected = false;\n\nclass Connection : public BLEServerCallbacks {\n  void onConnect(BLEServer *s) { connected = true; Serial.println(\"Phone connected\"); }\n  void onDisconnect(BLEServer *s) {\n    connected = false;\n    Serial.println(\"Phone left: advertising again\");\n    BLEDevice::startAdvertising();\n  }\n};\n\nclass LedWrite : public BLECharacteristicCallbacks {\n  void onWrite(BLECharacteristic *c) {\n    String v = c->getValue();\n    v.trim();\n    digitalWrite(2, v == \"on\" ? HIGH : LOW);\n    Serial.print(\"LED \");\n    Serial.println(v);\n  }\n};\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(2, OUTPUT);\n  dht.begin();\n  BLEDevice::init(\"ESP32 Thermo\");\n  server = BLEDevice::createServer();\n  server->setCallbacks(new Connection());\n  BLEService *service = server->createService(SERVICE_UUID);\n  temperature = service->createCharacteristic(TEMP_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);\n  temperature->addDescriptor(new BLE2902());\n  BLECharacteristic *led = service->createCharacteristic(LED_UUID, BLECharacteristic::PROPERTY_WRITE);\n  led->setCallbacks(new LedWrite());\n  service->start();\n  BLEDevice::getAdvertising()->addServiceUUID(SERVICE_UUID);\n  BLEDevice::startAdvertising();\n  Serial.println(\"Advertising as ESP32 Thermo\");\n}\n\nvoid loop() {\n  float t = dht.readTemperature();\n  if (!isnan(t)) {\n    char text[16];\n    snprintf(text, sizeof text, \"%.1f C\", t);\n    temperature->setValue(text);\n    if (connected) temperature->notify();\n  }\n  delay(2000);\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":60,"y":120},{"id":"dht1","type":"dht22","x":360,"y":220},{"id":"r1","type":"resistor","attrs":{"value":"220"},"x":330,"y":90},{"id":"led1","type":"led","attrs":{"color":"green"},"x":420,"y":60}],"wires":[["board:3V3","dht1:VCC"],["dht1:GND","board:GND.1"],["dht1:SDA","board:D4"],["board:D2","r1:1"],["r1:2","led1:A"],["led1:C","board:GND.2"]]}},{"id":"555-blinker","name":"555 timer blinker","summary":"A 555 blinks an LED by itself, about 7 times a second; the Uno counts its pulses and prints the frequency. Change R2 or C1 and watch it follow.","open":"https://lab.argynix.com/bench?example=555-blinker&run=1&view=3d","project":{"name":"555 timer blinker","ide":"arduino","board":"arduino-uno","code":"// A 555 timer blinking an LED by itself: no code drives it. R1 1 kΩ, R2 10 kΩ and C1\n// 10 µF set it to about 6.9 times a second: f = 1.44 / ((R1 + 2 × R2) × C1).\n// The Uno only listens: it counts the 555's pulses on pin 2 and prints the frequency.\n// Click R2 or C1 and change its value: the LED and the count follow.\n\nconst byte PULSE_PIN = 2;\nint last = LOW;\nunsigned long rises = 0;\nunsigned long since = 0;\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(PULSE_PIN, INPUT);\n  since = millis();\n}\n\nvoid loop() {\n  int now = digitalRead(PULSE_PIN);\n  if (now == HIGH && last == LOW) rises++;\n  last = now;\n  if (millis() - since >= 1000) {\n    Serial.print(\"The 555 runs at \");\n    Serial.print(rises);\n    Serial.println(\" Hz\");\n    rises = 0;\n    since += 1000;\n  }\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"u1","type":"ic-ne555","x":470,"y":300},{"id":"r1","type":"resistor","attrs":{"value":"1k"},"x":430,"y":200},{"id":"r2","type":"resistor","attrs":{"value":"10k"},"x":520,"y":240},{"id":"c1","type":"capacitor-electrolytic","attrs":{"value":"10µF"},"x":600,"y":300},{"id":"r3","type":"resistor","attrs":{"value":"220"},"x":440,"y":420},{"id":"led1","type":"led","attrs":{"color":"red"},"x":540,"y":400}],"wires":[["board:5V","u1:VCC"],["u1:VCC","u1:RESET"],["u1:VCC","r1:1"],["r1:2","u1:DIS"],["u1:DIS","r2:1"],["r2:2","u1:THR"],["u1:THR","u1:TRIG"],["u1:THR","c1:+"],["c1:-","board:GND.1"],["u1:GND","board:GND.1"],["u1:OUT","board:2"],["u1:OUT","r3:1"],["r3:2","led1:A"],["led1:C","board:GND.2"]]}},{"id":"lm358-night-light","name":"Op-amp night light (LM358)","summary":"An LM358 compares the light sensor with half the supply: when it gets dark the LED comes on, with no code in the way. The Uno reads both and prints them.","open":"https://lab.argynix.com/bench?example=lm358-night-light&run=1&view=3d","project":{"name":"Op-amp night light (LM358)","ide":"arduino","board":"arduino-uno","code":"// A night light made of an op-amp: the LM358 compares the light sensor's AO (higher\n// when it is dark) with 2.5 V from two 10 kΩ resistors, and its output lights the LED.\n// The Uno does not switch anything: it reads the comparator on pin 3 and the sensor on\n// A0, and says what changed. Set the light in the sensor's settings: under about\n// 100 lux the LED comes on.\n\nint was = -1;\n\nvoid setup() {\n  Serial.begin(115200);\n  pinMode(3, INPUT);\n}\n\nvoid loop() {\n  int dark = digitalRead(3);\n  if (dark != was) {\n    float volts = analogRead(A0) * 5.0 / 1023.0;\n    Serial.print(dark ? \"Dark: the LED is on\" : \"Light: the LED is off\");\n    Serial.print(\" (sensor at \");\n    Serial.print(volts, 2);\n    Serial.println(\" V)\");\n    was = dark;\n  }\n  delay(50);\n}\n","files":[],"parts":[{"id":"board","type":"arduino-uno","x":60,"y":200},{"id":"ldr1","type":"photoresistor-sensor","x":420,"y":40},{"id":"u1","type":"ic-lm358","x":500,"y":300},{"id":"ra","type":"resistor","attrs":{"value":"10k"},"x":420,"y":230},{"id":"rb","type":"resistor","attrs":{"value":"10k"},"x":420,"y":380},{"id":"r3","type":"resistor","attrs":{"value":"220"},"x":600,"y":380},{"id":"led1","type":"led","attrs":{"color":"yellow"},"x":690,"y":360}],"wires":[["board:5V","ldr1:VCC"],["ldr1:GND","board:GND.1"],["ldr1:AO","u1:IN1+"],["ldr1:AO","board:A0"],["board:5V","u1:VCC"],["u1:GND","board:GND.1"],["board:5V","ra:1"],["ra:2","u1:IN1-"],["u1:IN1-","rb:1"],["rb:2","board:GND.2"],["u1:OUT1","board:3"],["u1:OUT1","r3:1"],["r3:2","led1:A"],["led1:C","board:GND.3"]]}},{"id":"idf-blink","name":"ESP-IDF: blink","summary":"ESP-IDF’s blink example as it ships: the S3’s RGB LED through led_strip, settings from sdkconfig.h.","open":"https://lab.argynix.com/bench?example=idf-blink&run=1&view=3d","project":{"name":"ESP-IDF: blink","ide":"esp-idf","board":"esp32-s3-devkitc-1","code":"/* Blink, as ESP-IDF's get-started/blink example: the board's LED (an addressable RGB\n   LED on the S3 DevKitC-1, through the led_strip component) every second. Its\n   CONFIG_BLINK_* settings come from sdkconfig.h, as menuconfig leaves them. */\n#include <stdio.h>\n#include \"freertos/FreeRTOS.h\"\n#include \"freertos/task.h\"\n#include \"driver/gpio.h\"\n#include \"esp_log.h\"\n#include \"led_strip.h\"\n#include \"sdkconfig.h\"\n\nstatic const char *TAG = \"example\";\n\n#define BLINK_GPIO CONFIG_BLINK_GPIO\n\nstatic uint8_t s_led_state = 0;\n\n#ifdef CONFIG_BLINK_LED_STRIP\n\nstatic led_strip_handle_t led_strip;\n\nstatic void blink_led(void)\n{\n    if (s_led_state) {\n        led_strip_set_pixel(led_strip, 0, 16, 16, 16);\n        led_strip_refresh(led_strip);\n    } else {\n        led_strip_clear(led_strip);\n    }\n}\n\nstatic void configure_led(void)\n{\n    ESP_LOGI(TAG, \"Example configured to blink addressable LED!\");\n    led_strip_config_t strip_config = {\n        .strip_gpio_num = BLINK_GPIO,\n        .max_leds = 1,\n    };\n    led_strip_rmt_config_t rmt_config = {\n        .resolution_hz = 10 * 1000 * 1000,\n        .flags.with_dma = false,\n    };\n    ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));\n    led_strip_clear(led_strip);\n}\n\n#elif CONFIG_BLINK_LED_GPIO\n\nstatic void blink_led(void)\n{\n    gpio_set_level(BLINK_GPIO, s_led_state);\n}\n\nstatic void configure_led(void)\n{\n    ESP_LOGI(TAG, \"Example configured to blink GPIO LED!\");\n    gpio_reset_pin(BLINK_GPIO);\n    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);\n}\n\n#endif\n\nvoid app_main(void)\n{\n    configure_led();\n    while (1) {\n        ESP_LOGI(TAG, \"Turning the LED %s!\", s_led_state == true ? \"ON\" : \"OFF\");\n        blink_led();\n        s_led_state = !s_led_state;\n        vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);\n    }\n}\n","files":[],"parts":[{"id":"board","type":"esp32-s3-devkitc-1","x":120,"y":40}],"wires":[]}},{"id":"idf-gpio-isr","name":"ESP-IDF: button interrupt and a queue","summary":"An interrupt handler feeds a FreeRTOS queue; a task counts the presses and toggles GPIO2.","open":"https://lab.argynix.com/bench?example=idf-gpio-isr&run=1&view=3d","project":{"name":"ESP-IDF: button interrupt and a queue","ide":"esp-idf","board":"esp32-devkit-v1","code":"/* A button's interrupt feeds a FreeRTOS queue, as ESP-IDF's generic_gpio example: the\n   interrupt handler only sends the pin number; a task takes it from the queue,\n   counts the presses and toggles the LED on GPIO2. The button is on GPIO4, to GND. */\n#include <stdio.h>\n#include <inttypes.h>\n#include \"freertos/FreeRTOS.h\"\n#include \"freertos/task.h\"\n#include \"freertos/queue.h\"\n#include \"driver/gpio.h\"\n#include \"esp_log.h\"\n\n#define LED_GPIO GPIO_NUM_2\n#define BUTTON_GPIO GPIO_NUM_4\n\nstatic const char *TAG = \"gpio\";\nstatic QueueHandle_t gpio_evt_queue = NULL;\n\nstatic void IRAM_ATTR gpio_isr_handler(void *arg)\n{\n    uint32_t gpio_num = (uint32_t)arg;\n    xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);\n}\n\nstatic void button_task(void *arg)\n{\n    uint32_t io_num;\n    int presses = 0;\n    for (;;) {\n        if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {\n            presses++;\n            gpio_set_level(LED_GPIO, presses & 1);\n            ESP_LOGI(TAG, \"GPIO[%\" PRIu32 \"] interrupt, press %d, LED %s\", io_num, presses, presses & 1 ? \"on\" : \"off\");\n        }\n    }\n}\n\nvoid app_main(void)\n{\n    gpio_config_t led = {\n        .pin_bit_mask = 1ULL << LED_GPIO,\n        .mode = GPIO_MODE_OUTPUT,\n    };\n    gpio_config(&led);\n\n    gpio_config_t button = {\n        .pin_bit_mask = 1ULL << BUTTON_GPIO,\n        .mode = GPIO_MODE_INPUT,\n        .pull_up_en = GPIO_PULLUP_ENABLE,\n        .intr_type = GPIO_INTR_NEGEDGE,\n    };\n    gpio_config(&button);\n\n    gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));\n    xTaskCreate(button_task, \"button_task\", 2048, NULL, 10, NULL);\n\n    gpio_install_isr_service(0);\n    gpio_isr_handler_add(BUTTON_GPIO, gpio_isr_handler, (void *)BUTTON_GPIO);\n\n    ESP_LOGI(TAG, \"Press the button on GPIO%d\", BUTTON_GPIO);\n    for (;;) {\n        vTaskDelay(pdMS_TO_TICKS(1000));\n    }\n}\n","files":[],"parts":[{"id":"board","type":"esp32-devkit-v1","x":80,"y":80},{"id":"b1","type":"pushbutton","attrs":{"color":"green"},"x":300,"y":130}],"wires":[["b1:1.l","board:D4"],["b1:2.l","board:GND.1"]]}},{"id":"idf-i2c-lcd","name":"ESP-IDF: I2C LCD, two files","summary":"The I2C master driver and an LCD driver of its own (lcd1602.c, lcd1602.h) on the S3.","open":"https://lab.argynix.com/bench?example=idf-i2c-lcd&run=1&view=3d","project":{"name":"ESP-IDF: I2C LCD, two files","ide":"esp-idf","board":"esp32-s3-devkitc-1","code":"/* An I2C LCD with ESP-IDF's I2C master driver (v5.2 and later): the bus on GPIO8 (SDA)\n   and GPIO9 (SCL), the display at 0x27, its driver in lcd1602.c. A task counts up. */\n#include <stdio.h>\n#include \"freertos/FreeRTOS.h\"\n#include \"freertos/task.h\"\n#include \"driver/i2c_master.h\"\n#include \"esp_log.h\"\n#include \"lcd1602.h\"\n\nstatic const char *TAG = \"lcd\";\n\nvoid app_main(void)\n{\n    i2c_master_bus_config_t bus_config = {\n        .i2c_port = I2C_NUM_0,\n        .sda_io_num = GPIO_NUM_8,\n        .scl_io_num = GPIO_NUM_9,\n        .clk_source = I2C_CLK_SRC_DEFAULT,\n        .glitch_ignore_cnt = 7,\n        .flags.enable_internal_pullup = true,\n    };\n    i2c_master_bus_handle_t bus;\n    ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &bus));\n    ESP_ERROR_CHECK(i2c_master_probe(bus, 0x27, 100));\n    ESP_LOGI(TAG, \"LCD found at 0x27\");\n\n    lcd1602_t lcd;\n    ESP_ERROR_CHECK(lcd1602_init(&lcd, bus, 0x27));\n    lcd1602_print(&lcd, \"ESP-IDF on S3\");\n\n    for (int seconds = 0;; seconds++) {\n        char line[17];\n        snprintf(line, sizeof line, \"Uptime %5d s\", seconds);\n        lcd1602_move(&lcd, 0, 1);\n        lcd1602_print(&lcd, line);\n        vTaskDelay(pdMS_TO_TICKS(1000));\n    }\n}\n","files":[{"name":"lcd1602.h","code":"/* A 16x2 character LCD on a PCF8574 I2C backpack, for ESP-IDF's I2C master driver. */\n#pragma once\n#include \"driver/i2c_master.h\"\n\ntypedef struct {\n    i2c_master_dev_handle_t dev;\n} lcd1602_t;\n\nesp_err_t lcd1602_init(lcd1602_t *lcd, i2c_master_bus_handle_t bus, uint16_t address);\nvoid lcd1602_move(lcd1602_t *lcd, int col, int row);\nvoid lcd1602_print(lcd1602_t *lcd, const char *text);\n"},{"name":"lcd1602.c","code":"/* The PCF8574 backpack: P0 RS, P1 RW, P2 E, P3 backlight, P4-P7 D4-D7. The LCD runs in\n   4-bit mode; each nibble is latched by pulsing E. */\n#include \"lcd1602.h\"\n#include \"freertos/FreeRTOS.h\"\n#include \"freertos/task.h\"\n#include \"esp_rom_sys.h\"\n\n#define RS 0x01\n#define EN 0x04\n#define BACKLIGHT 0x08\n\nstatic esp_err_t nibble(lcd1602_t *lcd, uint8_t bits, uint8_t mode)\n{\n    uint8_t pulse[2] = { bits | mode | EN | BACKLIGHT, bits | mode | BACKLIGHT };\n    return i2c_master_transmit(lcd->dev, pulse, sizeof pulse, 100);\n}\n\nstatic esp_err_t send(lcd1602_t *lcd, uint8_t value, uint8_t mode)\n{\n    esp_err_t err = nibble(lcd, value & 0xF0, mode);\n    if (err == ESP_OK) err = nibble(lcd, (value << 4) & 0xF0, mode);\n    return err;\n}\n\nesp_err_t lcd1602_init(lcd1602_t *lcd, i2c_master_bus_handle_t bus, uint16_t address)\n{\n    i2c_device_config_t cfg = {\n        .dev_addr_length = I2C_ADDR_BIT_LEN_7,\n        .device_address = address,\n        .scl_speed_hz = 100000,\n    };\n    esp_err_t err = i2c_master_bus_add_device(bus, &cfg, &lcd->dev);\n    if (err != ESP_OK) return err;\n    vTaskDelay(pdMS_TO_TICKS(50));\n    nibble(lcd, 0x30, 0);\n    vTaskDelay(pdMS_TO_TICKS(5));\n    nibble(lcd, 0x30, 0);\n    esp_rom_delay_us(150);\n    nibble(lcd, 0x30, 0);\n    nibble(lcd, 0x20, 0); /* 4-bit mode */\n    send(lcd, 0x28, 0);   /* two lines, 5x8 */\n    send(lcd, 0x0C, 0);   /* display on */\n    send(lcd, 0x01, 0);   /* clear */\n    vTaskDelay(pdMS_TO_TICKS(2));\n    return send(lcd, 0x06, 0); /* left to right */\n}\n\nvoid lcd1602_move(lcd1602_t *lcd, int col, int row)\n{\n    send(lcd, 0x80 | (col + (row ? 0x40 : 0)), 0);\n}\n\nvoid lcd1602_print(lcd1602_t *lcd, const char *text)\n{\n    while (*text) send(lcd, (uint8_t)*text++, RS);\n}\n"}],"parts":[{"id":"board","type":"esp32-s3-devkitc-1","x":80,"y":40},{"id":"lcd1","type":"lcd1602","attrs":{"pins":"i2c","address":"0x27"},"x":300,"y":90}],"wires":[["lcd1:SDA","board:8"],["lcd1:SCL","board:9"],["lcd1:VCC","board:5V"],["lcd1:GND","board:GND.1"]]}},{"id":"idf-wifi-cloud","name":"ESP-IDF: Wi-Fi station to the cloud","summary":"ESP-IDF’s station example on the C6, then readings to ARGYNIX Cloud and its RGB LED from Connect.","open":"https://lab.argynix.com/bench?example=idf-wifi-cloud&run=1&view=3d","project":{"name":"ESP-IDF: Wi-Fi station to the cloud","ide":"esp-idf","board":"esp32-c6-devkitc-1","code":"/* Wi-Fi station, as ESP-IDF's wifi/getting_started/station example, then live in\n   ARGYNIX Cloud: the uptime and RSSI every 5 s, and a switch in Connect sending\n   \"setLed\" (true/false) lights the C6's RGB LED. Link the project from Live in Cloud. */\n#include <string.h>\n#include \"freertos/FreeRTOS.h\"\n#include \"freertos/task.h\"\n#include \"freertos/event_groups.h\"\n#include \"esp_system.h\"\n#include \"esp_wifi.h\"\n#include \"esp_event.h\"\n#include \"esp_log.h\"\n#include \"nvs_flash.h\"\n#include \"led_strip.h\"\n#include \"argynix_cloud.h\"\n\n#define WIFI_CONNECTED_BIT BIT0\n#define WIFI_FAIL_BIT      BIT1\n\nstatic const char *TAG = \"wifi station\";\nstatic EventGroupHandle_t s_wifi_event_group;\nstatic int s_retry_num = 0;\nstatic led_strip_handle_t led;\n\nstatic void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)\n{\n    if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {\n        esp_wifi_connect();\n    } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {\n        if (s_retry_num < CONFIG_ESP_MAXIMUM_RETRY) {\n            esp_wifi_connect();\n            s_retry_num++;\n            ESP_LOGI(TAG, \"retry to connect to the AP\");\n        } else {\n            xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);\n        }\n    } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {\n        ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;\n        ESP_LOGI(TAG, \"got ip:\" IPSTR, IP2STR(&event->ip_info.ip));\n        s_retry_num = 0;\n        xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);\n    }\n}\n\nstatic void on_command(const char *method, const char *params)\n{\n    if (strcmp(method, \"setLed\") == 0) {\n        bool on = strcmp(params, \"true\") == 0 || strcmp(params, \"1\") == 0;\n        if (on) led_strip_set_pixel(led, 0, 0, 40, 255);\n        else led_strip_set_pixel(led, 0, 0, 0, 0);\n        led_strip_refresh(led);\n        argynix_cloud_add_bool(\"led\", on);\n        argynix_cloud_publish();\n    }\n}\n\nvoid app_main(void)\n{\n    ESP_ERROR_CHECK(nvs_flash_init());\n    led_strip_config_t strip = { .strip_gpio_num = 8, .max_leds = 1 };\n    led_strip_rmt_config_t rmt = { .resolution_hz = 10 * 1000 * 1000 };\n    ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip, &rmt, &led));\n\n    s_wifi_event_group = xEventGroupCreate();\n    ESP_ERROR_CHECK(esp_netif_init());\n    ESP_ERROR_CHECK(esp_event_loop_create_default());\n    esp_netif_create_default_wifi_sta();\n    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();\n    ESP_ERROR_CHECK(esp_wifi_init(&cfg));\n\n    esp_event_handler_instance_t instance_any_id;\n    esp_event_handler_instance_t instance_got_ip;\n    ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id));\n    ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip));\n\n    wifi_config_t wifi_config = {\n        .sta = {\n            .ssid = CONFIG_ESP_WIFI_SSID,\n            .password = CONFIG_ESP_WIFI_PASSWORD,\n            .threshold.authmode = WIFI_AUTH_WPA2_PSK,\n            .sae_pwe_h2e = WPA3_SAE_PWE_BOTH,\n            .sae_h2e_identifier = \"\",\n        },\n    };\n    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));\n    ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));\n    ESP_ERROR_CHECK(esp_wifi_start());\n    ESP_LOGI(TAG, \"wifi_init_sta finished.\");\n\n    EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, pdFALSE, pdFALSE, portMAX_DELAY);\n    if (bits & WIFI_CONNECTED_BIT) {\n        ESP_LOGI(TAG, \"connected to ap SSID:%s\", CONFIG_ESP_WIFI_SSID);\n    } else {\n        ESP_LOGI(TAG, \"Failed to connect to SSID:%s\", CONFIG_ESP_WIFI_SSID);\n        return;\n    }\n\n    argynix_cloud_start(on_command);\n    for (int seconds = 0;; seconds += 5) {\n        int rssi = 0;\n        esp_wifi_sta_get_rssi(&rssi);\n        argynix_cloud_add_int(\"uptime\", seconds);\n        argynix_cloud_add_int(\"rssi\", rssi);\n        argynix_cloud_publish();\n        vTaskDelay(pdMS_TO_TICKS(5000));\n    }\n}\n","files":[],"parts":[{"id":"board","type":"esp32-c6-devkitc-1","x":120,"y":40}],"wires":[]}},{"id":"idf-deep-sleep","name":"ESP-IDF: deep sleep, RTC memory, NVS","summary":"The C3 sleeps and wakes three times; RTC memory and NVS keep their counts through it.","open":"https://lab.argynix.com/bench?example=idf-deep-sleep&run=1&view=3d","project":{"name":"ESP-IDF: deep sleep, RTC memory, NVS","ide":"esp-idf","board":"esp32-c3-devkitm-1","code":"/* Deep sleep: the board sleeps 2 s and starts again. A boot counter in RTC memory\n   (RTC_DATA_ATTR) survives the sleep; a counter in NVS survives everything. After\n   three sleeps it stays awake. */\n#include <stdio.h>\n#include <inttypes.h>\n#include \"freertos/FreeRTOS.h\"\n#include \"freertos/task.h\"\n#include \"esp_sleep.h\"\n#include \"esp_system.h\"\n#include \"esp_log.h\"\n#include \"nvs_flash.h\"\n#include \"nvs.h\"\n\nstatic const char *TAG = \"sleep\";\nstatic RTC_DATA_ATTR int boot_count = 0;\n\nvoid app_main(void)\n{\n    boot_count++;\n    ESP_ERROR_CHECK(nvs_flash_init());\n    nvs_handle_t nvs;\n    ESP_ERROR_CHECK(nvs_open(\"storage\", NVS_READWRITE, &nvs));\n    int32_t wakes = 0;\n    esp_err_t err = nvs_get_i32(nvs, \"wakes\", &wakes);\n    if (err == ESP_ERR_NVS_NOT_FOUND) ESP_LOGI(TAG, \"first boot: no count in NVS yet\");\n    wakes++;\n    ESP_ERROR_CHECK(nvs_set_i32(nvs, \"wakes\", wakes));\n    ESP_ERROR_CHECK(nvs_commit(nvs));\n    nvs_close(nvs);\n\n    esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();\n    ESP_LOGI(TAG, \"boot %d (RTC memory), start %\" PRId32 \" (NVS), woken by %s\", boot_count, wakes,\n             cause == ESP_SLEEP_WAKEUP_TIMER ? \"the timer\" : \"power-on\");\n\n    if (wakes < 4) {\n        ESP_LOGI(TAG, \"deep sleep for 2 s\");\n        esp_sleep_enable_timer_wakeup(2 * 1000 * 1000);\n        esp_deep_sleep_start();\n    }\n    ESP_LOGI(TAG, \"staying awake\");\n}\n","files":[],"parts":[{"id":"board","type":"esp32-c3-devkitm-1","x":120,"y":40}],"wires":[]}},{"id":"hal-blink","name":"STM32 HAL: blink and printf, CubeIDE layout","summary":"A CubeIDE project for the Blue Pill: 72 MHz from the crystal, PC13 blinking, printf out of USART1.","open":"https://lab.argynix.com/bench?example=hal-blink&run=1&view=3d","project":{"name":"STM32 HAL: blink and printf, CubeIDE layout","ide":"stm32-hal","board":"stm32-bluepill","code":"/* Blink and printf on the Blue Pill, as an STM32CubeIDE project: SystemClock_Config()\n   runs the 8 MHz crystal through the PLL (x9) to 72 MHz, PC13 (the board's LED, lit\n   when the pin is low) blinks every half second, and printf goes out of USART1\n   (PA9) through _write(). The Serial Monitor shows what USART1 sends. */\n#include \"main.h\"\n#include <stdio.h>\n\nUART_HandleTypeDef huart1;\n\nvoid SystemClock_Config(void);\nstatic void MX_GPIO_Init(void);\nstatic void MX_USART1_UART_Init(void);\n\n/* USER CODE BEGIN 0 */\nint _write(int file, char *ptr, int len)\n{\n  (void)file;\n  HAL_UART_Transmit(&huart1, (uint8_t *)ptr, (uint16_t)len, HAL_MAX_DELAY);\n  return len;\n}\n/* USER CODE END 0 */\n\nint main(void)\n{\n  HAL_Init();\n  SystemClock_Config();\n  MX_GPIO_Init();\n  MX_USART1_UART_Init();\n\n  /* USER CODE BEGIN 2 */\n  printf(\"SYSCLK %lu MHz, APB1 %lu MHz, APB2 %lu MHz\\r\\n\", HAL_RCC_GetSysClockFreq() / 1000000,\n         HAL_RCC_GetPCLK1Freq() / 1000000, HAL_RCC_GetPCLK2Freq() / 1000000);\n  uint32_t count = 0;\n  /* USER CODE END 2 */\n\n  while (1)\n  {\n    /* USER CODE BEGIN 3 */\n    HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);\n    count++;\n    printf(\"blink %lu, LED %s\\r\\n\", count, HAL_GPIO_ReadPin(LED_GPIO_Port, LED_Pin) == GPIO_PIN_RESET ? \"on\" : \"off\");\n    HAL_Delay(500);\n  }\n  /* USER CODE END 3 */\n}\n\nvoid SystemClock_Config(void)\n{\n  RCC_OscInitTypeDef RCC_OscInitStruct = {0};\n  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};\n\n  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;\n  RCC_OscInitStruct.HSEState = RCC_HSE_ON;\n  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;\n  RCC_OscInitStruct.HSIState = RCC_HSI_ON;\n  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;\n  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;\n  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;\n  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;\n  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;\n  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;\n  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;\n  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;\n  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}\n\nstatic void MX_USART1_UART_Init(void)\n{\n  huart1.Instance = USART1;\n  huart1.Init.BaudRate = 115200;\n  huart1.Init.WordLength = UART_WORDLENGTH_8B;\n  huart1.Init.StopBits = UART_STOPBITS_1;\n  huart1.Init.Parity = UART_PARITY_NONE;\n  huart1.Init.Mode = UART_MODE_TX_RX;\n  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;\n  huart1.Init.OverSampling = UART_OVERSAMPLING_16;\n  if (HAL_UART_Init(&huart1) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}\n\nstatic void MX_GPIO_Init(void)\n{\n  GPIO_InitTypeDef GPIO_InitStruct = {0};\n\n  __HAL_RCC_GPIOC_CLK_ENABLE();\n  __HAL_RCC_GPIOD_CLK_ENABLE();\n  __HAL_RCC_GPIOA_CLK_ENABLE();\n\n  HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);\n\n  GPIO_InitStruct.Pin = LED_Pin;\n  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\n  GPIO_InitStruct.Pull = GPIO_NOPULL;\n  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;\n  HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);\n}\n\nvoid Error_Handler(void)\n{\n  /* USER CODE BEGIN Error_Handler_Debug */\n  __disable_irq();\n  while (1)\n  {\n  }\n  /* USER CODE END Error_Handler_Debug */\n}\n","files":[{"name":"main.h","code":"#ifndef __MAIN_H\n#define __MAIN_H\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"stm32f1xx_hal.h\"\n\nvoid Error_Handler(void);\n\n/* Private defines */\n#define LED_Pin GPIO_PIN_13\n#define LED_GPIO_Port GPIOC\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* __MAIN_H */\n"},{"name":"stm32f1xx_it.c","code":"/* Interrupt handlers: the Cortex-M's own, then the peripherals'. */\n#include \"main.h\"\n#include \"stm32f1xx_it.h\"\n\nvoid NMI_Handler(void) { while (1) {} }\nvoid HardFault_Handler(void) { while (1) {} }\nvoid MemManage_Handler(void) { while (1) {} }\nvoid BusFault_Handler(void) { while (1) {} }\nvoid UsageFault_Handler(void) { while (1) {} }\nvoid SVC_Handler(void) {}\nvoid DebugMon_Handler(void) {}\nvoid PendSV_Handler(void) {}\n\nvoid SysTick_Handler(void)\n{\n  HAL_IncTick();\n}\n"},{"name":"stm32f1xx_it.h","code":"#ifndef __STM32F1xx_IT_H\n#define __STM32F1xx_IT_H\n\nvoid NMI_Handler(void);\nvoid HardFault_Handler(void);\nvoid SysTick_Handler(void);\n\n#endif\n"},{"name":"stm32f1xx_hal_msp.c","code":"/* Each peripheral's pins and clocks, as CubeMX writes them. */\n#include \"main.h\"\n\nvoid HAL_MspInit(void)\n{\n  __HAL_RCC_AFIO_CLK_ENABLE();\n  __HAL_RCC_PWR_CLK_ENABLE();\n  __HAL_AFIO_REMAP_SWJ_NOJTAG();\n}\n\nvoid HAL_UART_MspInit(UART_HandleTypeDef *huart)\n{\n  GPIO_InitTypeDef GPIO_InitStruct = {0};\n  if (huart->Instance == USART1)\n  {\n    __HAL_RCC_USART1_CLK_ENABLE();\n    __HAL_RCC_GPIOA_CLK_ENABLE();\n    /* PA9 USART1_TX, PA10 USART1_RX */\n    GPIO_InitStruct.Pin = GPIO_PIN_9;\n    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;\n    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;\n    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);\n    GPIO_InitStruct.Pin = GPIO_PIN_10;\n    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;\n    GPIO_InitStruct.Pull = GPIO_NOPULL;\n    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);\n  }\n}\n"}],"parts":[{"id":"board","type":"stm32-bluepill","x":120,"y":60}],"wires":[]}},{"id":"hal-exti","name":"STM32 HAL: button interrupt (EXTI)","summary":"On the Nucleo-F401RE, a falling edge on D2 runs HAL_GPIO_EXTI_Callback(), which toggles LD2.","open":"https://lab.argynix.com/bench?example=hal-exti&run=1&view=3d","project":{"name":"STM32 HAL: button interrupt (EXTI)","ide":"stm32-hal","board":"nucleo-f401re","code":"/* A button's interrupt on the Nucleo-F401RE, set up as CubeMX does: PA10 (D2) is an\n   EXTI line on its falling edge with the pull-up on. EXTI15_10_IRQHandler() in\n   stm32f4xx_it.c hands it to the HAL, which calls HAL_GPIO_EXTI_Callback() below: it\n   toggles LD2 (PA5) and counts the presses. printf goes out of USART2, the ST-LINK's\n   virtual COM port. Press the button. */\n#include \"main.h\"\n#include <stdio.h>\n\nUART_HandleTypeDef huart2;\n\n/* USER CODE BEGIN PV */\nstatic volatile uint32_t presses;\nstatic volatile uint32_t last_press_ms;\n/* USER CODE END PV */\n\nvoid SystemClock_Config(void);\nstatic void MX_GPIO_Init(void);\nstatic void MX_USART2_UART_Init(void);\n\n/* USER CODE BEGIN 0 */\nint _write(int file, char *ptr, int len)\n{\n  (void)file;\n  HAL_UART_Transmit(&huart2, (uint8_t *)ptr, (uint16_t)len, HAL_MAX_DELAY);\n  return len;\n}\n/* USER CODE END 0 */\n\nint main(void)\n{\n  HAL_Init();\n  SystemClock_Config();\n  MX_GPIO_Init();\n  MX_USART2_UART_Init();\n\n  /* USER CODE BEGIN 2 */\n  printf(\"Nucleo-F401RE at %lu MHz: press the button on D2\\r\\n\", SystemCoreClock / 1000000);\n  uint32_t shown = 0;\n  /* USER CODE END 2 */\n\n  while (1)\n  {\n    /* USER CODE BEGIN 3 */\n    if (presses != shown)\n    {\n      shown = presses;\n      printf(\"press %lu, LD2 %s\\r\\n\", shown, HAL_GPIO_ReadPin(LD2_GPIO_Port, LD2_Pin) == GPIO_PIN_SET ? \"on\" : \"off\");\n    }\n    HAL_Delay(10);\n  }\n  /* USER CODE END 3 */\n}\n\nvoid SystemClock_Config(void)\n{\n  RCC_OscInitTypeDef RCC_OscInitStruct = {0};\n  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};\n\n  __HAL_RCC_PWR_CLK_ENABLE();\n  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);\n\n  /* HSI 16 MHz / 16 x 336 / 4 = 84 MHz */\n  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;\n  RCC_OscInitStruct.HSIState = RCC_HSI_ON;\n  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;\n  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;\n  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;\n  RCC_OscInitStruct.PLL.PLLM = 16;\n  RCC_OscInitStruct.PLL.PLLN = 336;\n  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;\n  RCC_OscInitStruct.PLL.PLLQ = 7;\n  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;\n  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;\n  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;\n  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;\n  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;\n  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}\n\nstatic void MX_USART2_UART_Init(void)\n{\n  huart2.Instance = USART2;\n  huart2.Init.BaudRate = 115200;\n  huart2.Init.WordLength = UART_WORDLENGTH_8B;\n  huart2.Init.StopBits = UART_STOPBITS_1;\n  huart2.Init.Parity = UART_PARITY_NONE;\n  huart2.Init.Mode = UART_MODE_TX_RX;\n  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;\n  huart2.Init.OverSampling = UART_OVERSAMPLING_16;\n  if (HAL_UART_Init(&huart2) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}\n\nstatic void MX_GPIO_Init(void)\n{\n  GPIO_InitTypeDef GPIO_InitStruct = {0};\n\n  __HAL_RCC_GPIOC_CLK_ENABLE();\n  __HAL_RCC_GPIOH_CLK_ENABLE();\n  __HAL_RCC_GPIOA_CLK_ENABLE();\n\n  HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);\n\n  GPIO_InitStruct.Pin = BTN_Pin;\n  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;\n  GPIO_InitStruct.Pull = GPIO_PULLUP;\n  HAL_GPIO_Init(BTN_GPIO_Port, &GPIO_InitStruct);\n\n  GPIO_InitStruct.Pin = LD2_Pin;\n  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\n  GPIO_InitStruct.Pull = GPIO_NOPULL;\n  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;\n  HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);\n\n  HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);\n  HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);\n}\n\n/* USER CODE BEGIN 4 */\nvoid HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)\n{\n  if (GPIO_Pin != BTN_Pin) return;\n  uint32_t now = HAL_GetTick();\n  if (now - last_press_ms < 50) return; /* the contacts bouncing */\n  last_press_ms = now;\n  presses++;\n  HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);\n}\n/* USER CODE END 4 */\n\nvoid Error_Handler(void)\n{\n  /* USER CODE BEGIN Error_Handler_Debug */\n  __disable_irq();\n  while (1)\n  {\n  }\n  /* USER CODE END Error_Handler_Debug */\n}\n","files":[{"name":"main.h","code":"#ifndef __MAIN_H\n#define __MAIN_H\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"stm32f4xx_hal.h\"\n\nvoid Error_Handler(void);\n\n/* Private defines */\n#define BTN_Pin GPIO_PIN_10\n#define BTN_GPIO_Port GPIOA\n#define BTN_EXTI_IRQn EXTI15_10_IRQn\n#define LD2_Pin GPIO_PIN_5\n#define LD2_GPIO_Port GPIOA\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* __MAIN_H */\n"},{"name":"stm32f4xx_it.c","code":"/* Interrupt handlers: the Cortex-M's own, then the peripherals'. */\n#include \"main.h\"\n#include \"stm32f4xx_it.h\"\n\nvoid NMI_Handler(void) { while (1) {} }\nvoid HardFault_Handler(void) { while (1) {} }\nvoid MemManage_Handler(void) { while (1) {} }\nvoid BusFault_Handler(void) { while (1) {} }\nvoid UsageFault_Handler(void) { while (1) {} }\nvoid SVC_Handler(void) {}\nvoid DebugMon_Handler(void) {}\nvoid PendSV_Handler(void) {}\n\nvoid SysTick_Handler(void)\n{\n  HAL_IncTick();\n}\n\nvoid EXTI15_10_IRQHandler(void)\n{\n  HAL_GPIO_EXTI_IRQHandler(BTN_Pin);\n}\n"},{"name":"stm32f4xx_it.h","code":"#ifndef __STM32F4xx_IT_H\n#define __STM32F4xx_IT_H\n\nvoid NMI_Handler(void);\nvoid HardFault_Handler(void);\nvoid SysTick_Handler(void);\nvoid EXTI15_10_IRQHandler(void);\n\n#endif\n"},{"name":"stm32f4xx_hal_msp.c","code":"/* Each peripheral's pins and clocks, as CubeMX writes them. */\n#include \"main.h\"\n\nvoid HAL_MspInit(void)\n{\n  __HAL_RCC_SYSCFG_CLK_ENABLE();\n  __HAL_RCC_PWR_CLK_ENABLE();\n}\n\nvoid HAL_UART_MspInit(UART_HandleTypeDef *huart)\n{\n  GPIO_InitTypeDef GPIO_InitStruct = {0};\n  if (huart->Instance == USART2)\n  {\n    __HAL_RCC_USART2_CLK_ENABLE();\n    __HAL_RCC_GPIOA_CLK_ENABLE();\n    /* PA2 USART2_TX, PA3 USART2_RX */\n    GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3;\n    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;\n    GPIO_InitStruct.Pull = GPIO_NOPULL;\n    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;\n    GPIO_InitStruct.Alternate = GPIO_AF7_USART2;\n    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);\n  }\n}\n"}],"parts":[{"id":"board","type":"nucleo-f401re","x":40,"y":200},{"id":"b1","type":"pushbutton","attrs":{"color":"blue"},"x":520,"y":80}],"wires":[["b1:1.l","board:D2"],["b1:2.l","board:GND.1"]]}},{"id":"hal-pwm-adc","name":"STM32 HAL: pot to PWM (ADC and TIM2)","summary":"On the Nucleo-L476RG, ADC1 reads a pot on A0 and TIM2’s PWM sets LD2’s brightness to match.","open":"https://lab.argynix.com/bench?example=hal-pwm-adc&run=1&view=3d","project":{"name":"STM32 HAL: pot to PWM (ADC and TIM2)","ide":"stm32-hal","board":"nucleo-l476rg","code":"/* A pot dims an LED on the Nucleo-L476RG: ADC1 reads channel 5 (PA0, A0) and TIM2\n   channel 1 puts out 1 kHz PWM on PA5, which is LD2 and D13. The clock is the MSI\n   (4 MHz) through the PLL to 80 MHz, as CubeMX sets it; the ADC is calibrated first.\n   Turn the pot. */\n#include \"main.h\"\n#include <stdio.h>\n\nADC_HandleTypeDef hadc1;\nTIM_HandleTypeDef htim2;\nUART_HandleTypeDef huart2;\n\nvoid SystemClock_Config(void);\nstatic void MX_GPIO_Init(void);\nstatic void MX_ADC1_Init(void);\nstatic void MX_TIM2_Init(void);\nstatic void MX_USART2_UART_Init(void);\n\n/* USER CODE BEGIN 0 */\nint _write(int file, char *ptr, int len)\n{\n  (void)file;\n  HAL_UART_Transmit(&huart2, (uint8_t *)ptr, (uint16_t)len, HAL_MAX_DELAY);\n  return len;\n}\n/* USER CODE END 0 */\n\nint main(void)\n{\n  HAL_Init();\n  SystemClock_Config();\n  MX_GPIO_Init();\n  MX_ADC1_Init();\n  MX_TIM2_Init();\n  MX_USART2_UART_Init();\n\n  /* USER CODE BEGIN 2 */\n  HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);\n  HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);\n  printf(\"SYSCLK %lu MHz, PWM %lu Hz\\r\\n\", SystemCoreClock / 1000000,\n         SystemCoreClock / (htim2.Init.Prescaler + 1) / (htim2.Init.Period + 1));\n  uint32_t last_print = 0;\n  /* USER CODE END 2 */\n\n  while (1)\n  {\n    /* USER CODE BEGIN 3 */\n    HAL_ADC_Start(&hadc1);\n    if (HAL_ADC_PollForConversion(&hadc1, 10) == HAL_OK)\n    {\n      uint32_t raw = HAL_ADC_GetValue(&hadc1); /* 0 to 4095 */\n      uint32_t pulse = raw * (htim2.Init.Period + 1) / 4096;\n      __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, pulse);\n      if (HAL_GetTick() - last_print >= 250)\n      {\n        last_print = HAL_GetTick();\n        printf(\"ADC %4lu  %4lu mV  duty %3lu%%\\r\\n\", raw, raw * 3300 / 4095, pulse * 100 / (htim2.Init.Period + 1));\n      }\n    }\n    HAL_Delay(20);\n  }\n  /* USER CODE END 3 */\n}\n\nvoid SystemClock_Config(void)\n{\n  RCC_OscInitTypeDef RCC_OscInitStruct = {0};\n  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};\n\n  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  /* MSI 4 MHz / 1 x 40 / 2 = 80 MHz */\n  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;\n  RCC_OscInitStruct.MSIState = RCC_MSI_ON;\n  RCC_OscInitStruct.MSICalibrationValue = 0;\n  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;\n  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;\n  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;\n  RCC_OscInitStruct.PLL.PLLM = 1;\n  RCC_OscInitStruct.PLL.PLLN = 40;\n  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;\n  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;\n  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;\n  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;\n  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;\n  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;\n  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;\n  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;\n  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}\n\nstatic void MX_ADC1_Init(void)\n{\n  ADC_MultiModeTypeDef multimode = {0};\n  ADC_ChannelConfTypeDef sConfig = {0};\n\n  hadc1.Instance = ADC1;\n  hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;\n  hadc1.Init.Resolution = ADC_RESOLUTION_12B;\n  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;\n  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;\n  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;\n  hadc1.Init.LowPowerAutoWait = DISABLE;\n  hadc1.Init.ContinuousConvMode = DISABLE;\n  hadc1.Init.NbrOfConversion = 1;\n  hadc1.Init.DiscontinuousConvMode = DISABLE;\n  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;\n  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;\n  hadc1.Init.DMAContinuousRequests = DISABLE;\n  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;\n  hadc1.Init.OversamplingMode = DISABLE;\n  if (HAL_ADC_Init(&hadc1) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  multimode.Mode = ADC_MODE_INDEPENDENT;\n  if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  sConfig.Channel = ADC_CHANNEL_5;\n  sConfig.Rank = ADC_REGULAR_RANK_1;\n  sConfig.SamplingTime = ADC_SAMPLETIME_47CYCLES_5;\n  sConfig.SingleDiff = ADC_SINGLE_ENDED;\n  sConfig.OffsetNumber = ADC_OFFSET_NONE;\n  sConfig.Offset = 0;\n  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}\n\nstatic void MX_TIM2_Init(void)\n{\n  TIM_MasterConfigTypeDef sMasterConfig = {0};\n  TIM_OC_InitTypeDef sConfigOC = {0};\n\n  htim2.Instance = TIM2;\n  htim2.Init.Prescaler = 79; /* 80 MHz / 80 = 1 MHz */\n  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;\n  htim2.Init.Period = 999; /* 1 MHz / 1000 = 1 kHz */\n  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;\n  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;\n  if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;\n  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;\n  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  sConfigOC.OCMode = TIM_OCMODE_PWM1;\n  sConfigOC.Pulse = 0;\n  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;\n  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;\n  if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  HAL_TIM_MspPostInit(&htim2);\n}\n\nstatic void MX_USART2_UART_Init(void)\n{\n  huart2.Instance = USART2;\n  huart2.Init.BaudRate = 115200;\n  huart2.Init.WordLength = UART_WORDLENGTH_8B;\n  huart2.Init.StopBits = UART_STOPBITS_1;\n  huart2.Init.Parity = UART_PARITY_NONE;\n  huart2.Init.Mode = UART_MODE_TX_RX;\n  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;\n  huart2.Init.OverSampling = UART_OVERSAMPLING_16;\n  if (HAL_UART_Init(&huart2) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}\n\nstatic void MX_GPIO_Init(void)\n{\n  __HAL_RCC_GPIOC_CLK_ENABLE();\n  __HAL_RCC_GPIOH_CLK_ENABLE();\n  __HAL_RCC_GPIOA_CLK_ENABLE();\n}\n\nvoid Error_Handler(void)\n{\n  /* USER CODE BEGIN Error_Handler_Debug */\n  __disable_irq();\n  while (1)\n  {\n  }\n  /* USER CODE END Error_Handler_Debug */\n}\n","files":[{"name":"main.h","code":"#ifndef __MAIN_H\n#define __MAIN_H\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"stm32l4xx_hal.h\"\n\nvoid Error_Handler(void);\n\n/* Private defines */\n#define LD2_Pin GPIO_PIN_5\n#define LD2_GPIO_Port GPIOA\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* __MAIN_H */\n"},{"name":"stm32l4xx_it.c","code":"/* Interrupt handlers: the Cortex-M's own, then the peripherals'. */\n#include \"main.h\"\n#include \"stm32l4xx_it.h\"\n\nvoid NMI_Handler(void) { while (1) {} }\nvoid HardFault_Handler(void) { while (1) {} }\nvoid MemManage_Handler(void) { while (1) {} }\nvoid BusFault_Handler(void) { while (1) {} }\nvoid UsageFault_Handler(void) { while (1) {} }\nvoid SVC_Handler(void) {}\nvoid DebugMon_Handler(void) {}\nvoid PendSV_Handler(void) {}\n\nvoid SysTick_Handler(void)\n{\n  HAL_IncTick();\n}\n"},{"name":"stm32l4xx_it.h","code":"#ifndef __STM32L4xx_IT_H\n#define __STM32L4xx_IT_H\n\nvoid NMI_Handler(void);\nvoid HardFault_Handler(void);\nvoid SysTick_Handler(void);\n\n#endif\n"},{"name":"stm32l4xx_hal_msp.c","code":"/* Each peripheral's pins and clocks, as CubeMX writes them for the L476. */\n#include \"main.h\"\n\nvoid HAL_MspInit(void)\n{\n  __HAL_RCC_SYSCFG_CLK_ENABLE();\n  __HAL_RCC_PWR_CLK_ENABLE();\n}\n\nvoid HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)\n{\n  GPIO_InitTypeDef GPIO_InitStruct = {0};\n  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};\n  if (hadc->Instance == ADC1)\n  {\n    /* The ADC's clock: PLLSAI1 from the MSI, 4 MHz x 16 / 2 = 32 MHz */\n    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;\n    PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;\n    PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_MSI;\n    PeriphClkInit.PLLSAI1.PLLSAI1M = 1;\n    PeriphClkInit.PLLSAI1.PLLSAI1N = 16;\n    PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;\n    PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;\n    PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;\n    PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_ADC1CLK;\n    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)\n    {\n      Error_Handler();\n    }\n    __HAL_RCC_ADC_CLK_ENABLE();\n    __HAL_RCC_GPIOA_CLK_ENABLE();\n    /* PA0 ADC1_IN5 */\n    GPIO_InitStruct.Pin = GPIO_PIN_0;\n    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;\n    GPIO_InitStruct.Pull = GPIO_NOPULL;\n    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);\n  }\n}\n\nvoid HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim_pwm)\n{\n  if (htim_pwm->Instance == TIM2)\n  {\n    __HAL_RCC_TIM2_CLK_ENABLE();\n  }\n}\n\nvoid HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim)\n{\n  GPIO_InitTypeDef GPIO_InitStruct = {0};\n  if (htim->Instance == TIM2)\n  {\n    __HAL_RCC_GPIOA_CLK_ENABLE();\n    /* PA5 TIM2_CH1 */\n    GPIO_InitStruct.Pin = GPIO_PIN_5;\n    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;\n    GPIO_InitStruct.Pull = GPIO_NOPULL;\n    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;\n    GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;\n    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);\n  }\n}\n\nvoid HAL_UART_MspInit(UART_HandleTypeDef *huart)\n{\n  GPIO_InitTypeDef GPIO_InitStruct = {0};\n  if (huart->Instance == USART2)\n  {\n    __HAL_RCC_USART2_CLK_ENABLE();\n    __HAL_RCC_GPIOA_CLK_ENABLE();\n    /* PA2 USART2_TX, PA3 USART2_RX */\n    GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3;\n    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;\n    GPIO_InitStruct.Pull = GPIO_NOPULL;\n    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;\n    GPIO_InitStruct.Alternate = GPIO_AF7_USART2;\n    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);\n  }\n}\n"}],"parts":[{"id":"board","type":"nucleo-l476rg","x":40,"y":260},{"id":"pot1","type":"potentiometer","x":470,"y":80},{"id":"led1","type":"led","attrs":{"color":"yellow"},"x":300,"y":70}],"wires":[["pot1:VCC","board:3V3"],["pot1:GND","board:GND.2"],["pot1:SIG","board:A0"],["led1:A","board:D13"],["led1:C","board:GND.1"]]}},{"id":"hal-i2c-lcd","name":"STM32 HAL: I2C LCD, its own driver","summary":"On the Black Pill, HAL_I2C_Master_Transmit() drives a 16x2 LCD through a driver in lcd.c and lcd.h.","open":"https://lab.argynix.com/bench?example=hal-i2c-lcd&run=1&view=3d","project":{"name":"STM32 HAL: I2C LCD, its own driver","ide":"stm32-hal","board":"stm32-blackpill","code":"/* An I2C LCD on the Black Pill (STM32F411), with the HAL's I2C driver: I2C1 on PB6\n   (SCL) and PB7 (SDA) at 100 kHz, an LCD driver of its own in lcd.c and lcd.h, and\n   the 25 MHz crystal through the PLL to 100 MHz. HAL_I2C_IsDeviceReady() finds the\n   backpack first. */\n#include \"main.h\"\n#include <stdio.h>\n#include \"lcd.h\"\n\nI2C_HandleTypeDef hi2c1;\n\nvoid SystemClock_Config(void);\nstatic void MX_GPIO_Init(void);\nstatic void MX_I2C1_Init(void);\n\nint main(void)\n{\n  HAL_Init();\n  SystemClock_Config();\n  MX_GPIO_Init();\n  MX_I2C1_Init();\n\n  /* USER CODE BEGIN 2 */\n  if (HAL_I2C_IsDeviceReady(&hi2c1, LCD_ADDRESS, 3, 100) != HAL_OK)\n  {\n    printf(\"No LCD at 0x%02X: check SDA, SCL and its power\\n\", LCD_ADDRESS >> 1);\n    Error_Handler();\n  }\n  printf(\"LCD found at 0x%02X\\n\", LCD_ADDRESS >> 1);\n  lcd_init(&hi2c1);\n  char line[17];\n  snprintf(line, sizeof line, \"F411 at %luMHz\", SystemCoreClock / 1000000);\n  lcd_print_at(0, 0, line);\n  /* USER CODE END 2 */\n\n  while (1)\n  {\n    /* USER CODE BEGIN 3 */\n    snprintf(line, sizeof line, \"Up %lu s   \", HAL_GetTick() / 1000);\n    lcd_print_at(0, 1, line);\n    HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);\n    HAL_Delay(500);\n  }\n  /* USER CODE END 3 */\n}\n\nvoid SystemClock_Config(void)\n{\n  RCC_OscInitTypeDef RCC_OscInitStruct = {0};\n  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};\n\n  __HAL_RCC_PWR_CLK_ENABLE();\n  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);\n\n  /* HSE 25 MHz / 25 x 200 / 2 = 100 MHz */\n  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;\n  RCC_OscInitStruct.HSEState = RCC_HSE_ON;\n  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;\n  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;\n  RCC_OscInitStruct.PLL.PLLM = 25;\n  RCC_OscInitStruct.PLL.PLLN = 200;\n  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;\n  RCC_OscInitStruct.PLL.PLLQ = 4;\n  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)\n  {\n    Error_Handler();\n  }\n  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;\n  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;\n  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;\n  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;\n  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;\n  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}\n\nstatic void MX_I2C1_Init(void)\n{\n  hi2c1.Instance = I2C1;\n  hi2c1.Init.ClockSpeed = 100000;\n  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;\n  hi2c1.Init.OwnAddress1 = 0;\n  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;\n  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;\n  hi2c1.Init.OwnAddress2 = 0;\n  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;\n  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;\n  if (HAL_I2C_Init(&hi2c1) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}\n\nstatic void MX_GPIO_Init(void)\n{\n  GPIO_InitTypeDef GPIO_InitStruct = {0};\n\n  __HAL_RCC_GPIOC_CLK_ENABLE();\n  __HAL_RCC_GPIOH_CLK_ENABLE();\n  __HAL_RCC_GPIOB_CLK_ENABLE();\n\n  HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);\n  GPIO_InitStruct.Pin = LED_Pin;\n  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\n  GPIO_InitStruct.Pull = GPIO_NOPULL;\n  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;\n  HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);\n}\n\nvoid Error_Handler(void)\n{\n  /* USER CODE BEGIN Error_Handler_Debug */\n  __disable_irq();\n  while (1)\n  {\n  }\n  /* USER CODE END Error_Handler_Debug */\n}\n","files":[{"name":"main.h","code":"#ifndef __MAIN_H\n#define __MAIN_H\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"stm32f4xx_hal.h\"\n\nvoid Error_Handler(void);\n\n/* Private defines */\n#define LED_Pin GPIO_PIN_13\n#define LED_GPIO_Port GPIOC\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* __MAIN_H */\n"},{"name":"lcd.h","code":"/* A 16x2 character LCD on a PCF8574 I2C backpack, for the STM32 HAL's I2C driver. */\n#ifndef LCD_H\n#define LCD_H\n\n#include \"main.h\"\n\n/* The HAL takes the address shifted left: 0x27 is 0x4E. */\n#define LCD_ADDRESS (0x27 << 1)\n\nvoid lcd_init(I2C_HandleTypeDef *hi2c);\nvoid lcd_clear(void);\nvoid lcd_print_at(uint8_t col, uint8_t row, const char *text);\n\n#endif\n"},{"name":"lcd.c","code":"/* The PCF8574 backpack: P0 RS, P1 RW, P2 E, P3 backlight, P4-P7 D4-D7. The LCD runs in\n   4-bit mode, each half byte latched by a pulse on E. */\n#include \"lcd.h\"\n\n#define RS 0x01\n#define EN 0x04\n#define BACKLIGHT 0x08\n\nstatic I2C_HandleTypeDef *bus;\n\nstatic void send_half(uint8_t half, uint8_t mode)\n{\n  uint8_t data = (uint8_t)((half & 0xF0) | BACKLIGHT | mode);\n  uint8_t pulse[2] = {(uint8_t)(data | EN), data};\n  HAL_I2C_Master_Transmit(bus, LCD_ADDRESS, pulse, 2, 10);\n}\n\nstatic void send(uint8_t value, uint8_t mode)\n{\n  send_half(value & 0xF0, mode);\n  send_half((uint8_t)(value << 4), mode);\n}\n\nvoid lcd_init(I2C_HandleTypeDef *hi2c)\n{\n  bus = hi2c;\n  HAL_Delay(50);\n  send_half(0x30, 0);\n  HAL_Delay(5);\n  send_half(0x30, 0);\n  HAL_Delay(1);\n  send_half(0x30, 0);\n  send_half(0x20, 0); /* 4-bit */\n  send(0x28, 0);      /* two lines, 5x8 dots */\n  send(0x0C, 0);      /* display on, no cursor */\n  send(0x06, 0);      /* the cursor moves right */\n  lcd_clear();\n}\n\nvoid lcd_clear(void)\n{\n  send(0x01, 0);\n  HAL_Delay(2);\n}\n\nvoid lcd_print_at(uint8_t col, uint8_t row, const char *text)\n{\n  send((uint8_t)(0x80 | (col + (row ? 0x40 : 0x00))), 0);\n  while (*text) send((uint8_t)*text++, RS);\n}\n"},{"name":"stm32f4xx_it.c","code":"/* Interrupt handlers: the Cortex-M's own, then the peripherals'. */\n#include \"main.h\"\n#include \"stm32f4xx_it.h\"\n\nvoid NMI_Handler(void) { while (1) {} }\nvoid HardFault_Handler(void) { while (1) {} }\nvoid MemManage_Handler(void) { while (1) {} }\nvoid BusFault_Handler(void) { while (1) {} }\nvoid UsageFault_Handler(void) { while (1) {} }\nvoid SVC_Handler(void) {}\nvoid DebugMon_Handler(void) {}\nvoid PendSV_Handler(void) {}\n\nvoid SysTick_Handler(void)\n{\n  HAL_IncTick();\n}\n"},{"name":"stm32f4xx_it.h","code":"#ifndef __STM32F4xx_IT_H\n#define __STM32F4xx_IT_H\n\nvoid NMI_Handler(void);\nvoid HardFault_Handler(void);\nvoid SysTick_Handler(void);\n\n#endif\n"},{"name":"stm32f4xx_hal_msp.c","code":"/* Each peripheral's pins and clocks, as CubeMX writes them. */\n#include \"main.h\"\n\nvoid HAL_MspInit(void)\n{\n  __HAL_RCC_SYSCFG_CLK_ENABLE();\n  __HAL_RCC_PWR_CLK_ENABLE();\n}\n\nvoid HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)\n{\n  GPIO_InitTypeDef GPIO_InitStruct = {0};\n  if (hi2c->Instance == I2C1)\n  {\n    __HAL_RCC_GPIOB_CLK_ENABLE();\n    /* PB6 I2C1_SCL, PB7 I2C1_SDA */\n    GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;\n    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;\n    GPIO_InitStruct.Pull = GPIO_NOPULL;\n    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;\n    GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;\n    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);\n    __HAL_RCC_I2C1_CLK_ENABLE();\n  }\n}\n"}],"parts":[{"id":"board","type":"stm32-blackpill","x":60,"y":60},{"id":"lcd1","type":"lcd1602","attrs":{"pins":"i2c","address":"0x27"},"x":360,"y":80}],"wires":[["lcd1:SDA","board:PB7"],["lcd1:SCL","board:PB6"],["lcd1:VCC","board:5V"],["lcd1:GND","board:GND.1"]]}},{"id":"cmsis-blink","name":"STM32 registers: blink with CMSIS, no HAL","summary":"Bare-metal register code on the Blue Pill: the PLL to 72 MHz, SysTick, GPIOC->BSRR and USART1->DR.","open":"https://lab.argynix.com/bench?example=cmsis-blink&run=1&view=3d","project":{"name":"STM32 registers: blink with CMSIS, no HAL","ide":"stm32-hal","board":"stm32-bluepill","code":"/* A blink with no HAL at all: CMSIS register code on the Blue Pill. It starts the\n   8 MHz crystal and the PLL (x9) itself, as system_stm32f1xx.c does, makes PC13 an\n   output in GPIOC->CRH, counts milliseconds in SysTick_Handler and writes to USART1's\n   data register. The LED (lit when PC13 is low) flashes 100 ms every second. */\n#include \"stm32f1xx.h\"\n\nstatic volatile uint32_t ms;\n\nvoid SysTick_Handler(void)\n{\n  ms++;\n}\n\nstatic void delay_ms(uint32_t n)\n{\n  uint32_t start = ms;\n  while (ms - start < n) __WFI();\n}\n\nstatic void clock_72mhz(void)\n{\n  RCC->CR |= RCC_CR_HSEON;\n  while (!(RCC->CR & RCC_CR_HSERDY)) {}\n  FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_2;\n  RCC->CFGR |= RCC_CFGR_PPRE1_DIV2 | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL9;\n  RCC->CR |= RCC_CR_PLLON;\n  while (!(RCC->CR & RCC_CR_PLLRDY)) {}\n  RCC->CFGR = (RCC->CFGR & ~RCC_CFGR_SW) | RCC_CFGR_SW_PLL;\n  while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL) {}\n  SystemCoreClockUpdate();\n}\n\nstatic void uart_print(const char *s)\n{\n  while (*s)\n  {\n    while (!(USART1->SR & USART_SR_TXE)) {}\n    USART1->DR = (uint8_t)*s++;\n  }\n}\n\nstatic void uart_number(uint32_t v)\n{\n  char digits[11];\n  int i = 10;\n  digits[i] = 0;\n  do { digits[--i] = (char)('0' + v % 10); v /= 10; } while (v);\n  uart_print(&digits[i]);\n}\n\nint main(void)\n{\n  clock_72mhz();\n  SysTick_Config(SystemCoreClock / 1000);\n\n  RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_USART1EN;\n  /* PC13: output, 2 MHz, push-pull */\n  GPIOC->CRH = (GPIOC->CRH & ~(GPIO_CRH_MODE13 | GPIO_CRH_CNF13)) | GPIO_CRH_MODE13_1;\n  /* PA9: USART1 TX, alternate function push-pull */\n  GPIOA->CRH = (GPIOA->CRH & ~(GPIO_CRH_MODE9 | GPIO_CRH_CNF9)) | GPIO_CRH_MODE9_1 | GPIO_CRH_CNF9_1;\n  USART1->BRR = SystemCoreClock / 115200;\n  USART1->CR1 = USART_CR1_UE | USART_CR1_TE;\n\n  uart_print(\"SystemCoreClock = \");\n  uart_number(SystemCoreClock);\n  uart_print(\"\\r\\n\");\n\n  for (uint32_t n = 1;; n++)\n  {\n    GPIOC->BSRR = GPIO_BSRR_BR13; /* low: the LED on */\n    delay_ms(100);\n    GPIOC->BSRR = GPIO_BSRR_BS13;\n    delay_ms(900);\n    uart_print(\"flash \");\n    uart_number(n);\n    uart_print(\" at \");\n    uart_number(ms);\n    uart_print(\" ms\\r\\n\");\n  }\n}\n","files":[],"parts":[{"id":"board","type":"stm32-bluepill","x":120,"y":60}],"wires":[]}},{"id":"mp-blink","name":"MicroPython: blink","summary":"MicroPython’s own firmware on the real RP2040: the LED blinks, the board prints. No build.","open":"https://lab.argynix.com/bench?example=mp-blink&run=1&view=3d","project":{"name":"MicroPython: blink","ide":"micropython","board":"pi-pico","code":"# The Pico's LED blinks and the board prints. This is MicroPython's own firmware on the\n# exact RP2040: press Run and it starts at once, no build. When it stops, type into its REPL.\nfrom machine import Pin\nimport time\n\nled = Pin(\"LED\", Pin.OUT)\nfor n in range(20):\n    led.toggle()\n    print(\"blink\", n)\n    time.sleep(0.25)\nprint(\"done\")\n","files":[],"parts":[{"id":"board","type":"pi-pico","x":80,"y":60}],"wires":[]}},{"id":"mp-button","name":"MicroPython: button and LED","summary":"A button on GP14 toggles an LED on GP15 through an interrupt.","open":"https://lab.argynix.com/bench?example=mp-button&run=1&view=3d","project":{"name":"MicroPython: button and LED","ide":"micropython","board":"pi-pico","code":"# A button on GP14 (to ground, the pull-up inside) toggles the LED on GP15, through an\n# interrupt. Click the button while it runs.\nfrom machine import Pin\nimport time\n\nled = Pin(15, Pin.OUT)\nbutton = Pin(14, Pin.IN, Pin.PULL_UP)\npresses = 0\n\ndef pressed(pin):\n    global presses\n    presses += 1\n    led.toggle()\n\nbutton.irq(trigger=Pin.IRQ_FALLING, handler=pressed)\nwhile True:\n    print(\"presses:\", presses)\n    time.sleep(1)\n","files":[],"parts":[{"id":"board","type":"pi-pico","x":80,"y":60},{"id":"led1","type":"led","attrs":{"color":"green"},"x":340,"y":60},{"id":"btn1","type":"pushbutton","x":340,"y":200}],"wires":[["led1:A","board:GP15"],["led1:C","board:GND.4"],["btn1:1.l","board:GP14"],["btn1:2.l","board:GND.5"]]}},{"id":"mp-dimmer","name":"MicroPython: knob dimmer","summary":"A potentiometer on GP26 sets an LED’s brightness on GP15 with PWM.","open":"https://lab.argynix.com/bench?example=mp-dimmer&run=1&view=3d","project":{"name":"MicroPython: knob dimmer","ide":"micropython","board":"pi-pico","code":"# A potentiometer on GP26 (ADC 0) sets the brightness of the LED on GP15 (PWM).\n# Turn the knob while it runs.\nfrom machine import ADC, PWM, Pin\nimport time\n\nknob = ADC(26)\nled = PWM(Pin(15))\nled.freq(1000)\nwhile True:\n    level = knob.read_u16()\n    led.duty_u16(level)\n    print(\"level\", level * 100 // 65535, \"%\")\n    time.sleep(0.2)\n","files":[],"parts":[{"id":"board","type":"pi-pico","x":80,"y":60},{"id":"led1","type":"led","attrs":{"color":"yellow"},"x":340,"y":60},{"id":"pot1","type":"potentiometer","x":340,"y":220}],"wires":[["led1:A","board:GP15"],["led1:C","board:GND.4"],["pot1:SIG","board:GP26"],["pot1:VCC","board:3V3"],["pot1:GND","board:GND.6"]]}},{"id":"mp-neopixel","name":"MicroPython: NeoPixel ring","summary":"A colour runs round a 16-pixel ring on GP16, with the neopixel module.","open":"https://lab.argynix.com/bench?example=mp-neopixel&run=1&view=3d","project":{"name":"MicroPython: NeoPixel ring","ide":"micropython","board":"pi-pico","code":"# A colour runs round a 16-pixel ring on GP16. The neopixel module sends the bits with\n# WS2812 timing through machine.bitstream, which counts the CPU's cycles.\nfrom machine import Pin\nfrom neopixel import NeoPixel\nimport time\n\nring = NeoPixel(Pin(16), 16)\nhue = 0\nwhile True:\n    for i in range(16):\n        c = (hue + i * 16) % 256\n        ring[i] = (c, 255 - c, (c * 3) % 256) if i % 4 == 0 else (0, 0, 0)\n    ring.write()\n    hue = (hue + 8) % 256\n    time.sleep(0.1)\n","files":[],"parts":[{"id":"board","type":"pi-pico","x":80,"y":60},{"id":"ring1","type":"led-ring","attrs":{"pixels":"16"},"x":340,"y":60}],"wires":[["ring1:DIN","board:GP16"],["ring1:VCC","board:VBUS"],["ring1:GND","board:GND.4"]]}},{"id":"mp-pio","name":"MicroPython: PIO, a WS2812 driver in four instructions","summary":"A PIO program written in Python drives a 16-pixel ring: the RP2040’s own state machine shifts out every bit.","open":"https://lab.argynix.com/bench?example=mp-pio&run=1&view=3d","project":{"name":"MicroPython: PIO, a WS2812 driver in four instructions","ide":"micropython","board":"pi-pico","code":"# The RP2040's PIO: a state machine runs this four-instruction program, shifting each\n# 24-bit colour out on GP16 with WS2812 timing (8 MHz, 10 cycles a bit). The CPU only\n# hands it words.\nimport array, time\nfrom machine import Pin\nimport rp2\n\n@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True, pull_thresh=24)\ndef ws2812():\n    T1, T2, T3 = 2, 5, 3\n    wrap_target()\n    label(\"bitloop\")\n    out(x, 1)             .side(0) [T3 - 1]\n    jmp(not_x, \"do_zero\") .side(1) [T1 - 1]\n    jmp(\"bitloop\")        .side(1) [T2 - 1]\n    label(\"do_zero\")\n    nop()                 .side(0) [T2 - 1]\n    wrap()\n\nsm = rp2.StateMachine(0, ws2812, freq=8_000_000, sideset_base=Pin(16))\nsm.active(1)\npixels = array.array(\"I\", [0] * 16)\n\ndef grb(r, g, b):\n    return (g << 16) | (r << 8) | b\n\nstep = 0\nwhile True:\n    for i in range(16):\n        on = (i + step) % 16 < 4\n        pixels[i] = grb(0, 40 + 12 * i, 160) if on else grb(0, 0, 0)\n    sm.put(pixels, 8)\n    step += 1\n    time.sleep(0.08)\n","files":[],"parts":[{"id":"board","type":"pi-pico","x":80,"y":60},{"id":"ring1","type":"led-ring","attrs":{"pixels":"16"},"x":340,"y":60}],"wires":[["ring1:DIN","board:GP16"],["ring1:VCC","board:VBUS"],["ring1:GND","board:GND.4"]]}}]}