diff --git "a/outputInstruct.json" "b/outputInstruct.json" new file mode 100644--- /dev/null +++ "b/outputInstruct.json" @@ -0,0 +1,572 @@ +[ + { + "instruction": "Generate a diagram.json code for Simon says game", + "input": "#include \"pitches.h\"\n\n/* Constants - define pin numbers for LEDs,\n buttons and speaker, and also the game tones: */\nconst uint8_t ledPins[] = {9, 10, 11, 12};\nconst uint8_t buttonPins[] = {2, 3, 4, 5};\n#define SPEAKER_PIN 8\n\n// These are connected to 74HC595 shift register (used to show game score):\nconst int LATCH_PIN = A1; // 74HC595 pin 12\nconst int DATA_PIN = A0; // 74HC595pin 14\nconst int CLOCK_PIN = A2; // 74HC595 pin 11\n\n#define MAX_GAME_LENGTH 100\n\nconst int gameTones[] = { NOTE_G3, NOTE_C4, NOTE_E4, NOTE_G5};\n\n/* Global variables - store the game state */\nuint8_t gameSequence[MAX_GAME_LENGTH] = {0};\nuint8_t gameIndex = 0;\n\n/**\n Set up the Arduino board and initialize Serial communication\n*/\nvoid setup() {\n Serial.begin(9600);\n for (byte i = 0; i < 4; i++) {\n pinMode(ledPins[i], OUTPUT);\n pinMode(buttonPins[i], INPUT_PULLUP);\n }\n pinMode(SPEAKER_PIN, OUTPUT);\n pinMode(LATCH_PIN, OUTPUT);\n pinMode(CLOCK_PIN, OUTPUT);\n pinMode(DATA_PIN, OUTPUT);\n\n // The following line primes the random number generator.\n // It assumes pin A3 is floating (disconnected):\n randomSeed(analogRead(A3));\n}\n\n/* Digit table for the 7-segment display */\nconst uint8_t digitTable[] = {\n 0b11000000,\n 0b11111001,\n 0b10100100,\n 0b10110000,\n 0b10011001,\n 0b10010010,\n 0b10000010,\n 0b11111000,\n 0b10000000,\n 0b10010000,\n};\nconst uint8_t DASH = 0b10111111;\n\nvoid sendScore(uint8_t high, uint8_t low) {\n digitalWrite(LATCH_PIN, LOW);\n shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, low);\n shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, high);\n digitalWrite(LATCH_PIN, HIGH);\n}\n\nvoid displayScore() {\n int high = gameIndex % 100 / 10;\n int low = gameIndex % 10;\n sendScore(high ? digitTable[high] : 0xff, digitTable[low]);\n}\n\n/**\n Lights the given LED and plays a suitable tone\n*/\nvoid lightLedAndPlayTone(byte ledIndex) {\n digitalWrite(ledPins[ledIndex], HIGH);\n tone(SPEAKER_PIN, gameTones[ledIndex]);\n delay(300);\n digitalWrite(ledPins[ledIndex], LOW);\n noTone(SPEAKER_PIN);\n}\n\n/**\n Plays the current sequence of notes that the user has to repeat\n*/\nvoid playSequence() {\n for (int i = 0; i < gameIndex; i++) {\n byte currentLed = gameSequence[i];\n lightLedAndPlayTone(currentLed);\n delay(50);\n }\n}\n\n/**\n Waits until the user pressed one of the buttons,\n and returns the index of that button\n*/\nbyte readButtons() {\n while (true) {\n for (byte i = 0; i < 4; i++) {\n byte buttonPin = buttonPins[i];\n if (digitalRead(buttonPin) == LOW) {\n return i;\n }\n }\n delay(1);\n }\n}\n\n/**\n Play the game over sequence, and report the game score\n*/\nvoid gameOver() {\n Serial.print(\"Game over! your score: \");\n Serial.println(gameIndex - 1);\n gameIndex = 0;\n delay(200);\n\n // Play a Wah-Wah-Wah-Wah sound\n tone(SPEAKER_PIN, NOTE_DS5);\n delay(300);\n tone(SPEAKER_PIN, NOTE_D5);\n delay(300);\n tone(SPEAKER_PIN, NOTE_CS5);\n delay(300);\n for (byte i = 0; i < 10; i++) {\n for (int pitch = -10; pitch <= 10; pitch++) {\n tone(SPEAKER_PIN, NOTE_C5 + pitch);\n delay(5);\n }\n }\n noTone(SPEAKER_PIN);\n\n sendScore(DASH, DASH);\n delay(500);\n}\n\n/**\n Get the user's input and compare it with the expected sequence.\n*/\nbool checkUserSequence() {\n for (int i = 0; i < gameIndex; i++) {\n byte expectedButton = gameSequence[i];\n byte actualButton = readButtons();\n lightLedAndPlayTone(actualButton);\n if (expectedButton != actualButton) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n Plays a hooray sound whenever the user finishes a level\n*/\nvoid playLevelUpSound() {\n tone(SPEAKER_PIN, NOTE_E4);\n delay(150);\n tone(SPEAKER_PIN, NOTE_G4);\n delay(150);\n tone(SPEAKER_PIN, NOTE_E5);\n delay(150);\n tone(SPEAKER_PIN, NOTE_C5);\n delay(150);\n tone(SPEAKER_PIN, NOTE_D5);\n delay(150);\n tone(SPEAKER_PIN, NOTE_G5);\n delay(150);\n noTone(SPEAKER_PIN);\n}\n\n/**\n The main game loop\n*/\nvoid loop() {\n displayScore();\n\n // Add a random color to the end of the sequence\n gameSequence[gameIndex] = random(0, 4);\n gameIndex++;\n if (gameIndex >= MAX_GAME_LENGTH) {\n gameIndex = MAX_GAME_LENGTH - 1;\n }\n\n playSequence();\n if (!checkUserSequence()) {\n gameOver();\n }\n\n delay(300);\n\n if (gameIndex > 0) {\n playLevelUpSound();\n delay(300);\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 183, \"left\": 18.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"buzzer\",\n \"top\": 16,\n \"left\": 124,\n \"attrs\": { \"volume\": \"0.1\" }\n },\n { \"type\": \"wokwi-led\", \"id\": \"led-red\", \"top\": 10, \"left\": 6, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led-green\",\n \"top\": 73,\n \"left\": 6,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led-blue\",\n \"top\": 10,\n \"left\": 270,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led-yellow\",\n \"top\": 73,\n \"left\": 270,\n \"attrs\": { \"color\": \"yellow\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn-red\",\n \"top\": 10,\n \"left\": 46,\n \"attrs\": { \"color\": \"red\", \"key\": \"1\", \"label\": \"1\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn-green\",\n \"top\": 76,\n \"left\": 46,\n \"attrs\": { \"color\": \"green\", \"key\": \"2\", \"label\": \"2\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn-blue\",\n \"top\": 10,\n \"left\": 200,\n \"attrs\": { \"color\": \"blue\", \"key\": \"3\", \"label\": \"3\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn-yellow\",\n \"top\": 76,\n \"left\": 200,\n \"attrs\": { \"color\": \"yellow\", \"key\": \"4\", \"label\": \"4\" }\n },\n {\n \"type\": \"wokwi-74hc595\",\n \"id\": \"sr1\",\n \"top\": 171.8,\n \"left\": 361.16,\n \"rotate\": 180,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-74hc595\",\n \"id\": \"sr2\",\n \"top\": 171.8,\n \"left\": 457.16,\n \"rotate\": 180,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-7segment\", \"id\": \"sevseg1\", \"top\": 47.16, \"left\": 379.48, \"attrs\": {} },\n { \"type\": \"wokwi-7segment\", \"id\": \"sevseg2\", \"top\": 47.16, \"left\": 446.68, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"uno:GND.1\", \"buzzer:1\", \"black\", [ \"v-12\", \"*\", \"h0\" ] ],\n [ \"uno:2\", \"btn-yellow:1.l\", \"gold\", [ \"v-48\", \"*\", \"h-6\" ] ],\n [ \"uno:GND.1\", \"btn-yellow:2.r\", \"black\", [ \"v-12\", \"*\", \"h6\" ] ],\n [ \"uno:3\", \"btn-blue:1.l\", \"blue\", [ \"v-44\", \"*\", \"h-10\" ] ],\n [ \"uno:GND.1\", \"btn-blue:2.r\", \"black\", [ \"v-12\", \"*\", \"h6\" ] ],\n [ \"uno:4\", \"btn-green:2.r\", \"green\", [ \"v-40\", \"*\", \"h6\" ] ],\n [ \"uno:GND.1\", \"btn-green:1.l\", \"black\", [ \"v-12\", \"*\", \"h-6\" ] ],\n [ \"uno:5\", \"btn-red:2.r\", \"orange\", [ \"v-36\", \"*\", \"h10\" ] ],\n [ \"uno:GND.1\", \"btn-red:1.l\", \"black\", [ \"v-12\", \"*\", \"h-6\" ] ],\n [ \"uno:8\", \"buzzer:2\", \"purple\", [ \"v-32\", \"*\", \"h0\" ] ],\n [ \"uno:9\", \"led-yellow:A\", \"gold\", [ \"v-28\", \"*\", \"h0\" ] ],\n [ \"uno:GND.1\", \"led-yellow:C\", \"black\", [ \"v-12\", \"*\", \"h-15\", \"v4\" ] ],\n [ \"uno:10\", \"led-blue:A\", \"blue\", [ \"v-24\", \"*\", \"h8\" ] ],\n [ \"uno:GND.1\", \"led-blue:C\", \"black\", [ \"v-12\", \"*\", \"h-15\", \"v4\" ] ],\n [ \"uno:11\", \"led-green:A\", \"green\", [ \"v-20\", \"*\", \"h0\" ] ],\n [ \"uno:GND.1\", \"led-green:C\", \"black\", [ \"v-12\", \"*\", \"h-8\", \"v4\" ] ],\n [ \"uno:12\", \"led-red:A\", \"orange\", [ \"v-16\", \"*\", \"h6\" ] ],\n [ \"uno:GND.1\", \"led-red:C\", \"black\", [ \"v-12\", \"*\", \"h-8\", \"v4\" ] ],\n [ \"uno:5V\", \"sr1:VCC\", \"red\", [ \"v57.5\", \"h253.4\" ] ],\n [ \"uno:A2\", \"sr1:SHCP\", \"gray\", [ \"v19.1\", \"h138.4\" ] ],\n [ \"uno:A1\", \"sr1:STCP\", \"purple\", [ \"v28.7\", \"h157.5\" ] ],\n [ \"uno:A0\", \"sr1:DS\", \"blue\", [ \"v38.3\", \"h186.2\" ] ],\n [ \"sr1:SHCP\", \"sr2:SHCP\", \"gray\", [ \"v47\", \"h106.12\" ] ],\n [ \"sr1:STCP\", \"sr2:STCP\", \"purple\", [ \"v37.4\", \"h96.52\" ] ],\n [ \"sr1:Q7S\", \"sr2:DS\", \"blue\", [ \"h0.52\", \"v56.6\", \"h144\" ] ],\n [ \"sr1:VCC\", \"sr1:MR\", \"red\", [ \"v17\", \"h-57.6\" ] ],\n [ \"sr1:VCC\", \"sr2:MR\", \"red\", [ \"v17\", \"h38.4\" ] ],\n [ \"sr1:VCC\", \"sr2:VCC\", \"red\", [ \"v17\", \"h96\" ] ],\n [ \"sr1:OE\", \"sr2:OE\", \"black\", [ \"v26.6\", \"h96\" ] ],\n [ \"sr1:MR\", \"sevseg1:COM.1\", \"red\", [ \"v17\", \"h-57.6\", \"v-96\", \"h76.8\" ] ],\n [ \"sevseg1:COM.1\", \"sevseg2:COM.1\", \"red\", [ \"h0\", \"v9.6\", \"h57.6\" ] ],\n [ \"sr2:Q0\", \"sevseg2:A\", \"green\", [ \"v7.4\", \"h28.8\", \"v-182.4\", \"h-67.2\" ] ],\n [ \"sr2:Q1\", \"sevseg2:B\", \"green\", [ \"v0\", \"h9.6\", \"v-134.4\", \"h-48\" ] ],\n [ \"sr2:Q2\", \"sevseg2:C\", \"green\", [ \"v-38.4\", \"h-38.4\" ] ],\n [ \"sr2:Q3\", \"sevseg2:D\", \"green\", [ \"v-33.6\", \"h-33.6\", \"v-9.6\", \"h-14.4\" ] ],\n [ \"sr2:Q4\", \"sevseg2:E\", \"green\", [ \"v-28.8\", \"h-28.8\", \"v-9.6\", \"h-14.4\" ] ],\n [ \"sr2:Q5\", \"sevseg2:F\", \"green\", [ \"v-24\", \"h-24\", \"v-9.6\", \"h-24\", \"v-110.4\", \"h19.2\" ] ],\n [ \"sr2:Q6\", \"sevseg2:G\", \"green\", [ \"v-19.2\", \"h-43.2\", \"v-115.2\", \"h14.4\" ] ],\n [ \"sr1:GND\", \"sr2:GND\", \"black\", [ \"v-9.6\", \"h96\" ] ],\n [ \"sr1:Q1\", \"sevseg1:B\", \"green\", [ \"v-134.4\", \"h-19.2\" ] ],\n [ \"sr1:Q2\", \"sevseg1:C\", \"green\", [ \"v-38.4\", \"h-19.2\" ] ],\n [ \"sr1:Q3\", \"sevseg1:D\", \"green\", [ \"v-33.6\", \"h-24\" ] ],\n [ \"sr1:Q4\", \"sevseg1:E\", \"green\", [ \"v-28.8\", \"h-28.8\" ] ],\n [ \"uno:GND.3\", \"sr1:GND\", \"black\", [ \"v47.9\", \"h157.6\", \"v-259.2\", \"h9.6\" ] ],\n [ \"sr1:GND\", \"sr1:OE\", \"black\", [ \"v-9.6\", \"h-9.6\", \"v67.2\", \"h172.8\" ] ],\n [ \"sr1:Q0\", \"sevseg1:A\", \"green\", [ \"v65\", \"h-76.8\", \"v-240\", \"h57.6\" ] ],\n [ \"sr1:Q5\", \"sevseg1:F\", \"green\", [ \"v-24\", \"h-19.2\", \"v-110.4\", \"h19.2\" ] ],\n [ \"sr1:Q6\", \"sevseg1:G\", \"green\", [ \"v-19.2\", \"h-14.4\", \"v-110.4\", \"h14.4\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for servos dancing", + "input": "#include \n\n#define NUM_SERVOS 32\nServo myServo[NUM_SERVOS];\n\nvoid setup() \n{\n // Attach pins from the Arduino Mega board to the Servo objects.\n // Starting from pin 22, there happen to be exactly 32 pins on the double row pins.\n for( int i=0; i=0; r--)\n {\n for( int i=0; i (NUM_SERVOS / 2))\n d = NUM_SERVOS - d;\n\n int angle = 90 - (10 * d);\n if( angle < 0)\n angle = 0;\n myServo[j].write( angle);\n }\n delay(40);\n }\n }\n\n // Sequence four.\n // A \"compass\"\n // Start by pointing upwards\n int pointer = NUM_SERVOS * 3 / 4;\n showPointer( pointer);\n delay( 1000); // let the viewer get used to new pattern\n\n for( int i=0; i<5; i++)\n {\n showPointer( --pointer);\n delay( 150);\n }\n delay( 200);\n for( int i=0; i<9; i++)\n {\n showPointer( ++pointer);\n delay( 150);\n }\n delay( 200);\n for( int i=0; i<5; i++)\n {\n showPointer( --pointer);\n delay( 150);\n }\n delay( 200);\n for( int i=0; i<4; i++)\n {\n showPointer( ++pointer);\n delay( 150);\n }\n delay( 160);\n for( int i=0; i<2; i++)\n {\n showPointer( --pointer);\n delay( 150);\n }\n delay( 80);\n for( int i=0; i<1; i++)\n {\n showPointer( ++pointer);\n delay( 150);\n }\n\n delay( 2000);\n}\n\n// This function makes a \"pointer\" with the servos.\n// It is used to create the \"compass\".\n// The parameter 's' is the servo motor that has the pointer.\n// It is allowed that 's' is below zero or larger than the numbers of servo motors.\nvoid showPointer( int s)\n{\n int pointerA = s % NUM_SERVOS; // Using the '%' (remainder) for valid number\n int pointerB = (s + 1) % NUM_SERVOS; // pointer is made with the next servo motor\n int tailA = (s + 16) % NUM_SERVOS;\n int tailB = (s + 17) % NUM_SERVOS;\n\n // make pointer with servo motor s and s+1.\n myServo[pointerA].write(180-56);\n myServo[pointerB].write(56);\n\n // make tail with servo motor s+16 and s+17.\n myServo[tailA].write(95);\n myServo[tailB].write(85);\n\n // Set servos right of pointer\n int n = (NUM_SERVOS / 2) - 2;\n int start = pointerB + 1;\n for( int i=0; i=0; i--)\n {\n float rotate = float( i) * (360.0 / float( NUM_SERVOS));\n float rad = rotate / 360.0 * 2.0 * M_PI;\n float top = (300.0 * sin( rad)) + 300.0;\n float left = (300.0 * cos( rad)) + 300.0;\n Serial.print( \" {\\n\");\n Serial.print( \" \\\"type\\\": \\\"wokwi-servo\\\",\\n\");\n Serial.print( \" \\\"id\\\": \\\"servo\");\n Serial.print( i);\n Serial.print( \"\\\",\\n\");\n Serial.print( \" \\\"top\\\": \");\n Serial.print( top);\n Serial.print( \",\\n\");\n Serial.print( \" \\\"left\\\": \");\n Serial.print( left);\n Serial.print( \",\\n\");\n Serial.print( \" \\\"rotate\\\": \");\n Serial.print( rotate);\n Serial.print( \",\\n\");\n Serial.print( \" \\\"attrs\\\": { \\\"hornColor\\\": \\\"Red\\\" }\\n\");\n Serial.print( \" }\");\n if( i != 0)\n Serial.print( \",\");\n Serial.print( \"\\n\");\n } \n\n Serial.print( \" ],\\n\");\n Serial.print( \" \\\"connections\\\": [\\n\");\n\n for( int i=0; i> 6);\n sy1 = sy1 + (sx1 >> 6);\n sx2 = sx2 - (sy2 >> 5);\n sy2 = sy2 + (sx2 >> 5);\n\n static byte travel = 0;\n travel--;\n byte *dst = fb;\n byte output = 0;\n int8_t x_offset = (sx1 >> 8) - X_SEGMENTS * 4;\n int8_t y_offset = (sx2 >> 8) - Y_SEGMENTS * 4;\n\n uint8_t screenx, screeny, xroot, yroot;\n uint16_t xsumsquares, ysumsquares, xnextsquare, ynextsquare;\n int8_t x, y;\n\n // offset the origin in screen space\n x = x_offset;\n y = y_offset;\n ysumsquares = x_offset * x_offset + y * y;\n yroot = int(sqrtf(ysumsquares));\n ynextsquare = yroot*yroot;\n\n // Quadrant II (top-left)\n screeny = Y_SEGMENTS * 8;\n while (y < 0 && screeny) {\n x = x_offset;\n screenx = X_SEGMENTS * 8;\n xsumsquares = ysumsquares;\n xroot = yroot;\n if (x < 0) {\n xnextsquare = xroot * xroot;\n while (x < 0 && screenx) {\n screenx--;\n output <<= 1;\n output |= ((xroot + travel) & 8) >> 3;\n if (!(screenx & 7))\n *dst++ = output;\n xsumsquares += 2 * x++ + 1;\n if (xsumsquares < xnextsquare)\n xnextsquare -= 2 * xroot-- - 1;\n }\n }\n // Quadrant I (top right)\n if (screenx) {\n xnextsquare = (xroot + 1) * (xroot + 1);\n while (screenx) {\n screenx--;\n output <<= 1;\n output |= ((xroot + travel) & 8) >> 3;\n if (!(screenx & 7))\n *dst++ = output;\n xsumsquares += 2 * x++ + 1;\n if (xsumsquares >= xnextsquare)\n xnextsquare += 2 * ++xroot + 1;\n }\n }\n ysumsquares += 2 * y++ + 1;\n if (ysumsquares < ynextsquare)\n ynextsquare -= 2 * yroot-- - 1;\n screeny--;\n }\n // Quadrant III (bottom left)\n ynextsquare = (yroot + 1) * (yroot + 1);\n while (screeny) {\n x = x_offset;\n screenx = X_SEGMENTS * 8;\n xsumsquares = ysumsquares;\n xroot = yroot;\n if (x < 0) {\n xnextsquare = xroot * xroot;\n while (x < 0 && screenx) {\n screenx--;\n output <<= 1;\n output |= ((xroot + travel) & 8) >> 3;\n if (!(screenx & 7))\n *dst++ = output;\n xsumsquares += 2 * x++ + 1;\n if (xsumsquares < xnextsquare)\n xnextsquare -= 2 * xroot-- - 1;\n }\n }\n // Quadrant IV (bottom right)\n if (screenx) {\n xnextsquare = (xroot + 1) * (xroot + 1);\n while (screenx--) {\n output <<= 1;\n output |= ((xroot + travel) & 8) >> 3;\n if (!(screenx & 7))\n *dst++ = output;\n xsumsquares += 2 * x++ + 1;\n if (xsumsquares >= xnextsquare)\n xnextsquare += 2 * ++xroot + 1;\n }\n }\n ysumsquares += 2 * y++ + 1;\n if (ysumsquares >= ynextsquare)\n ynextsquare += 2 * ++yroot + 1;\n screeny--;\n }\n\n show();\n}\n\n\nvoid set_pixel(uint8_t x, uint8_t y, uint8_t mode) {\n byte *addr = &fb[x / 8 + y * X_SEGMENTS];\n byte mask = 128 >> (x % 8);\n switch (mode) {\n case 0: // clear pixel\n *addr &= ~mask;\n break;\n case 1: // plot pixel\n *addr |= mask;\n break;\n case 2: // XOR pixel\n *addr ^= mask;\n break;\n }\n}\n\n\nvoid safe_pixel(uint8_t x, uint8_t y, uint8_t mode) {\n if ((x >= X_SEGMENTS * 8) || (y >= Y_SEGMENTS * 8))\n return;\n set_pixel(x, y, mode);\n}\n\n\n// turn off every LED in the framebuffer\nvoid clear() {\n byte *addr = fb;\n for (byte i = 0; i < 8 * NUM_SEGMENTS; i++)\n *addr++ = 0;\n}\n\n\n// send the raster order framebuffer in the correct order\n// for the boustrophedon layout of daisy-chained MAX7219s\nvoid show() {\n for (byte row = 0; row < 8; row++) {\n digitalWrite(CS, LOW);\n byte segment = NUM_SEGMENTS;\n while (segment--) {\n byte x = segment % X_SEGMENTS;\n byte y = segment / X_SEGMENTS * 8;\n byte addr = (row + y) * X_SEGMENTS;\n\n if (segment & X_SEGMENTS) { // odd rows of segments\n shiftOut(DIN, CLK, MSBFIRST, 8 - row);\n shiftOut(DIN, CLK, LSBFIRST, fb[addr + x]);\n } else { // even rows of segments\n shiftOut(DIN, CLK, MSBFIRST, 1 + row);\n shiftOut(DIN, CLK, MSBFIRST, fb[addr - x + X_SEGMENTS - 1]);\n }\n }\n digitalWrite(CS, HIGH);\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"sutaburosu\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-arduino-mega\",\n \"id\": \"mega\",\n \"top\": -177.58,\n \"left\": 252.33,\n \"rotate\": 90,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"matrix1\",\n \"top\": -126.7,\n \"left\": -79.5,\n \"attrs\": { \"chain\": \"4\", \"layout\": \"fc16\" }\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"matrix2\",\n \"top\": -52.5,\n \"left\": -79.5,\n \"rotate\": 180,\n \"attrs\": { \"chain\": \"4\", \"layout\": \"fc16\" }\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"matrix3\",\n \"top\": 22.46,\n \"left\": -78.96,\n \"attrs\": { \"chain\": \"4\", \"layout\": \"fc16\" }\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"matrix4\",\n \"top\": 96.8,\n \"left\": -79.5,\n \"rotate\": 180,\n \"attrs\": { \"chain\": \"4\", \"layout\": \"fc16\" }\n }\n ],\n \"connections\": [\n [ \"matrix1:GND.2\", \"matrix2:GND\", \"black\", [ \"h-47.8\", \"v89.07\" ] ],\n [ \"matrix1:DOUT\", \"matrix2:DIN\", \"blue\", [ \"h-38.2\", \"v69.87\" ] ],\n [ \"matrix1:CS.2\", \"matrix2:CS\", \"green\", [ \"h-28.6\", \"v50.67\" ] ],\n [ \"matrix1:CLK.2\", \"matrix2:CLK\", \"orange\", [ \"h-19\", \"v31.47\" ] ],\n [ \"matrix2:CLK.2\", \"matrix3:CLK\", \"orange\", [ \"h58.3\", \"v110.3\" ] ],\n [ \"matrix2:CS.2\", \"matrix3:CS\", \"green\", [ \"h48.7\", \"v91.1\" ] ],\n [ \"matrix2:DOUT\", \"matrix3:DIN\", \"blue\", [ \"h39.1\", \"v71.9\" ] ],\n [ \"matrix2:GND.2\", \"matrix3:GND\", \"black\", [ \"h29.5\", \"v52.7\" ] ],\n [ \"matrix3:V+\", \"matrix2:V+.2\", \"red\", [ \"h19.2\", \"v-31.46\" ] ],\n [ \"matrix2:V+\", \"matrix1:V+.2\", \"red\", [ \"h-56.74\", \"v-110.5\" ] ],\n [ \"matrix4:V+\", \"matrix3:V+.2\", \"red\", [ \"h-56.74\", \"v-115.8\" ] ],\n [ \"matrix3:GND.2\", \"matrix4:GND\", \"black\", [ \"h-47.84\", \"v93.34\" ] ],\n [ \"matrix4:DIN\", \"matrix3:DOUT\", \"blue\", [ \"h-37.54\", \"v-67.8\" ] ],\n [ \"matrix4:CS\", \"matrix3:CS.2\", \"green\", [ \"h-27.94\", \"v-58.2\" ] ],\n [ \"matrix4:CLK\", \"matrix3:CLK.2\", \"orange\", [ \"h-18.34\", \"v-39\" ] ],\n [ \"mega:5V\", \"matrix1:V+\", \"red\", [ \"h-33.66\", \"v-77.39\" ] ],\n [ \"mega:GND.2\", \"matrix1:GND\", \"black\", [ \"h-42.41\", \"v-79.48\" ] ],\n [ \"mega:11\", \"matrix1:DIN\", \"blue\", [ \"h20.97\", \"v249.88\", \"h-211.2\", \"v-211.2\" ] ],\n [ \"mega:10\", \"matrix1:CS\", \"green\", [ \"h30.57\", \"v249.98\", \"h-230.4\", \"v-220.8\" ] ],\n [ \"mega:13\", \"matrix1:CLK\", \"orange\", [ \"h40.17\", \"v288.08\", \"h-249.6\", \"v-220.8\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for mini piano", + "input": "#include \"pitches.h\"\n\n#define SPEAKER_PIN 8\n\nconst uint8_t buttonPins[] = { 12, 11, 10, 9, 7, 6, 5, 4 };\nconst int buttonTones[] = {\n NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,\n NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5\n};\nconst int numTones = sizeof(buttonPins) / sizeof(buttonPins[0]);\n\nvoid setup() {\n for (uint8_t i = 0; i < numTones; i++) {\n pinMode(buttonPins[i], INPUT_PULLUP);\n }\n pinMode(SPEAKER_PIN, OUTPUT);\n}\n\nvoid loop() {\n int pitch = 0;\n for (uint8_t i = 0; i < numTones; i++) {\n if (digitalRead(buttonPins[i]) == LOW) {\n pitch = buttonTones[i];\n }\n }\n if (pitch) {\n tone(SPEAKER_PIN, pitch);\n } else {\n noTone(SPEAKER_PIN);\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 185, \"left\": 71, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"buzzer\",\n \"top\": 220,\n \"left\": 380,\n \"rotate\": 90,\n \"attrs\": { \"volume\": \"0.2\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": 70,\n \"left\": 0,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"red\", \"key\": \"1\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn2\",\n \"top\": 70,\n \"left\": 50,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"orange\", \"key\": \"2\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn3\",\n \"top\": 70,\n \"left\": 100,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"yellow\", \"key\": \"3\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn4\",\n \"top\": 70,\n \"left\": 150,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"green\", \"key\": \"4\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn5\",\n \"top\": 70,\n \"left\": 200,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"cyan\", \"key\": \"5\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn6\",\n \"top\": 70,\n \"left\": 250,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"blue\", \"key\": \"6\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn7\",\n \"top\": 70,\n \"left\": 300,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"purple\", \"key\": \"7\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn8\",\n \"top\": 70,\n \"left\": 350,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"red\", \"key\": \"8\" }\n }\n ],\n \"connections\": [\n [ \"uno:GND.1\", \"buzzer:1\", \"black\", [ \"v-16\", \"*\", \"h-18\" ] ],\n [ \"uno:8\", \"buzzer:2\", \"gold\", [ \"v-24\", \"*\", \"h-10\" ] ],\n [ \"uno:12\", \"btn1:1.r\", \"red\", [ \"v-24\", \"h0\" ] ],\n [ \"uno:GND.1\", \"btn1:2.r\", \"black\", [ \"v-16\", \"h0\" ] ],\n [ \"uno:11\", \"btn2:1.r\", \"orange\", [ \"v-32\", \"h0\" ] ],\n [ \"uno:GND.1\", \"btn2:2.r\", \"black\", [ \"v-16\", \"h0\" ] ],\n [ \"uno:10\", \"btn3:1.r\", \"yellow\", [ \"v-38\", \"h0\" ] ],\n [ \"uno:GND.1\", \"btn3:2.r\", \"black\", [ \"v-16\", \"h0\" ] ],\n [ \"uno:9\", \"btn4:1.r\", \"green\", [ \"v-46\", \"h20\" ] ],\n [ \"uno:GND.1\", \"btn4:2.r\", \"black\", [ \"v-16\", \"h0\" ] ],\n [ \"uno:7\", \"btn5:1.r\", \"cyan\", [ \"v-56\", \"h0\" ] ],\n [ \"uno:GND.1\", \"btn5:2.r\", \"black\", [ \"v-16\", \"h0\" ] ],\n [ \"uno:6\", \"btn6:1.r\", \"blue\", [ \"v-48\", \"h0\" ] ],\n [ \"uno:GND.1\", \"btn6:2.r\", \"black\", [ \"v-16\", \"h0\" ] ],\n [ \"uno:5\", \"btn7:1.r\", \"purple\", [ \"v-40\", \"h0\" ] ],\n [ \"uno:GND.1\", \"btn7:2.r\", \"black\", [ \"v-16\", \"h0\" ] ],\n [ \"uno:4\", \"btn8:1.r\", \"red\", [ \"v-32\", \"h0\" ] ],\n [ \"uno:GND.1\", \"btn8:2.r\", \"black\", [ \"v-16\", \"h0\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for alarm clock with RTC", + "input": "/**\n Arduino Digital Alarm Clock\n\n Copyright (C) 2020, Uri Shaked.\n Released under the MIT License.\n\n*/\n\n#include \n#include \"Button.h\"\n#include \"AlarmTone.h\"\n#include \"Clock.h\"\n#include \"config.h\"\n\nconst int COLON_PIN = 13;\nconst int SPEAKER_PIN = A3;\n\nButton hourButton(A0);\nButton minuteButton(A1);\nButton alarmButton(A2);\n\nAlarmTone alarmTone;\nClock clock;\nSevSeg sevseg;\n\nenum DisplayState {\n DisplayClock,\n DisplayAlarmStatus,\n DisplayAlarmTime,\n DisplayAlarmActive,\n DisplaySnooze,\n};\n\nDisplayState displayState = DisplayClock;\nlong lastStateChange = 0;\n\nvoid changeDisplayState(DisplayState newValue) {\n displayState = newValue;\n lastStateChange = millis();\n}\n\nlong millisSinceStateChange() {\n return millis() - lastStateChange;\n}\n\nvoid setColon(bool value) {\n digitalWrite(COLON_PIN, value ? LOW : HIGH);\n}\n\nvoid displayTime() {\n DateTime now = clock.now();\n bool blinkState = now.second() % 2 == 0;\n sevseg.setNumber(now.hour() * 100 + now.minute());\n setColon(blinkState);\n}\n\nvoid clockState() {\n displayTime();\n\n if (alarmButton.read() == Button::RELEASED && clock.alarmActive()) {\n // Read alarmButton has_changed() to clear its state\n alarmButton.has_changed();\n changeDisplayState(DisplayAlarmActive);\n return;\n }\n\n if (hourButton.pressed()) {\n clock.incrementHour();\n }\n if (minuteButton.pressed()) {\n clock.incrementMinute();\n }\n if (alarmButton.pressed()) {\n clock.toggleAlarm();\n changeDisplayState(DisplayAlarmStatus);\n }\n}\n\nvoid alarmStatusState() {\n setColon(false);\n sevseg.setChars(clock.alarmEnabled() ? \" on\" : \" off\");\n if (millisSinceStateChange() > ALARM_STATUS_DISPLAY_TIME) {\n changeDisplayState(clock.alarmEnabled() ? DisplayAlarmTime : DisplayClock);\n return;\n }\n}\n\nvoid alarmTimeState() {\n DateTime alarm = clock.alarmTime();\n sevseg.setNumber(alarm.hour() * 100 + alarm.minute(), -1);\n\n if (millisSinceStateChange() > ALARM_HOUR_DISPLAY_TIME || alarmButton.pressed()) {\n changeDisplayState(DisplayClock);\n return;\n }\n\n if (hourButton.pressed()) {\n clock.incrementAlarmHour();\n lastStateChange = millis();\n }\n if (minuteButton.pressed()) {\n clock.incrementAlarmMinute();\n lastStateChange = millis();\n }\n if (alarmButton.pressed()) {\n changeDisplayState(DisplayClock);\n }\n}\n\nvoid alarmState() {\n displayTime();\n\n if (alarmButton.read() == Button::RELEASED) {\n alarmTone.play();\n }\n if (alarmButton.pressed()) {\n alarmTone.stop();\n }\n if (alarmButton.released()) {\n alarmTone.stop();\n bool longPress = alarmButton.repeat_count() > 0;\n if (longPress) {\n clock.stopAlarm();\n changeDisplayState(DisplayClock);\n } else {\n clock.snooze();\n changeDisplayState(DisplaySnooze);\n }\n }\n}\n\nvoid snoozeState() {\n sevseg.setChars(\"****\");\n if (millisSinceStateChange() > SNOOZE_DISPLAY_TIME) {\n changeDisplayState(DisplayClock);\n return;\n }\n}\n\nvoid setup() {\n Serial.begin(115200);\n\n clock.begin();\n\n hourButton.begin();\n hourButton.set_repeat(500, 200);\n\n minuteButton.begin();\n minuteButton.set_repeat(500, 200);\n\n alarmButton.begin();\n alarmButton.set_repeat(1000, -1);\n\n alarmTone.begin(SPEAKER_PIN);\n\n pinMode(COLON_PIN, OUTPUT);\n\n byte digits = 4;\n byte digitPins[] = {2, 3, 4, 5};\n byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12};\n bool resistorsOnSegments = false;\n bool updateWithDelays = false;\n bool leadingZeros = true;\n bool disableDecPoint = true;\n sevseg.begin(DISPLAY_TYPE, digits, digitPins, segmentPins, resistorsOnSegments,\n updateWithDelays, leadingZeros, disableDecPoint);\n sevseg.setBrightness(90);\n}\n\nvoid loop() {\n sevseg.refreshDisplay();\n\n switch (displayState) {\n case DisplayClock:\n clockState();\n break;\n\n case DisplayAlarmStatus:\n alarmStatusState();\n break;\n\n case DisplayAlarmTime:\n alarmTimeState();\n break;\n\n case DisplayAlarmActive:\n alarmState();\n break;\n\n case DisplaySnooze:\n snoozeState();\n break;\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-7segment\",\n \"id\": \"7segment\",\n \"top\": -29.04,\n \"left\": 330.64,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"commonPin\": \"anode\", \"digits\": \"4\", \"colon\": \"1\" }\n },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"buzzer1\",\n \"top\": 190.17,\n \"left\": 466.82,\n \"rotate\": 90,\n \"hide\": false,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"pushbutton1\",\n \"top\": 110,\n \"left\": 300,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"label\": \"Hours\", \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"pushbutton2\",\n \"top\": 110,\n \"left\": 380,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"label\": \"Minutes\", \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"pushbutton3\",\n \"top\": 110,\n \"left\": 460,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"label\": \"Alarm\" }\n },\n {\n \"type\": \"wokwi-ds1307\",\n \"id\": \"ds1307\",\n \"top\": 235.82,\n \"left\": 283.79,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-arduino-uno\",\n \"id\": \"arduino\",\n \"top\": 0,\n \"left\": 0,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": {}\n }\n ],\n \"connections\": [\n [ \"7segment:DIG1\", \"arduino:2\", \"gold\", [ \"v-20\", \"h0\" ] ],\n [ \"7segment:DIG2\", \"arduino:3\", \"green\", [ \"v-24\", \"h0\" ] ],\n [ \"7segment:DIG3\", \"arduino:4\", \"orange\", [ \"v-28\", \"h0\" ] ],\n [ \"7segment:DIG4\", \"arduino:5\", \"purple\", [ \"v28\", \"h-150\", \"*\", \"v-16\" ] ],\n [ \"7segment:A\", \"arduino:6\", \"gray\", [ \"v-16\", \"h0\" ] ],\n [ \"7segment:B\", \"arduino:7\", \"purple\", [ \"v-36\", \"h0\" ] ],\n [ \"7segment:C\", \"arduino:8\", \"blue\", [\"v20\", \"h-120\", \"*\", \"v-20\"] ],\n [ \"7segment:D\", \"arduino:9\", \"cyan\", [ \"v16\", \"h-94\", \"*\", \"v-24\" ] ],\n [ \"7segment:E\", \"arduino:10\", \"green\", [\"v12\", \"h-80\", \"*\", \"v-28\"] ],\n [ \"7segment:F\", \"arduino:11\", \"brown\", [ \"v-40\", \"h0\" ] ],\n [ \"7segment:G\", \"arduino:12\", \"orange\", [\"v24\", \"h-134\", \"*\", \"v-32\"] ],\n [ \"7segment:CLN\", \"arduino:13\", \"cyan\", [ \"v-44\", \"h0\" ] ],\n [ \"7segment:COM\", \"arduino:5V\", \"red\", [ \"v300\", \"h0\" ] ],\n [ \"buzzer1:1\", \"arduino:GND.2\", \"black\", [] ],\n [ \"buzzer1:2\", \"arduino:A3\", \"orange\", [] ],\n [ \"pushbutton1:1.l\", \"arduino:A0\", \"green\", [ \"h-4\", \"v0\", \"*\", \"v20\" ] ],\n [ \"pushbutton1:2.l\", \"arduino:GND.2\", \"black\", [ \"*\", \"v34\" ] ],\n [ \"pushbutton2:1.l\", \"arduino:A1\", \"gray\", [ \"h-4\", \"v0\", \"*\", \"v24\" ] ],\n [ \"pushbutton2:2.l\", \"arduino:GND.2\", \"black\", [ \"*\", \"v34\" ] ],\n [ \"pushbutton3:1.l\", \"arduino:A2\", \"purple\", [ \"h-4\", \"v0\", \"*\", \"v28\" ] ],\n [ \"pushbutton3:2.l\", \"arduino:GND.2\", \"black\", [ \"*\", \"v34\" ] ],\n [ \"ds1307:GND\", \"arduino:GND.2\", \"black\", [] ],\n [ \"ds1307:5V\", \"arduino:5V\", \"red\", [] ],\n [ \"ds1307:SDA\", \"arduino:A4\", \"blue\", [] ],\n [ \"ds1307:SCL\", \"arduino:A5\", \"gold\", [] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for electronic safe", + "input": "/**\n Arduino Electronic Safe\n\n Copyright (C) 2020, Uri Shaked.\n Released under the MIT License.\n*/\n\n#include \n#include \n#include \n#include \"SafeState.h\"\n#include \"icons.h\"\n\n/* Locking mechanism definitions */\n#define SERVO_PIN 6\n#define SERVO_LOCK_POS 20\n#define SERVO_UNLOCK_POS 90\nServo lockServo;\n\n/* Display */\nLiquidCrystal lcd(12, 11, 10, 9, 8, 7);\n\n/* Keypad setup */\nconst byte KEYPAD_ROWS = 4;\nconst byte KEYPAD_COLS = 4;\nbyte rowPins[KEYPAD_ROWS] = {5, 4, 3, 2};\nbyte colPins[KEYPAD_COLS] = {A3, A2, A1, A0};\nchar keys[KEYPAD_ROWS][KEYPAD_COLS] = {\n {'1', '2', '3', 'A'},\n {'4', '5', '6', 'B'},\n {'7', '8', '9', 'C'},\n {'*', '0', '#', 'D'}\n};\n\nKeypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);\n\n/* SafeState stores the secret code in EEPROM */\nSafeState safeState;\n\nvoid lock() {\n lockServo.write(SERVO_LOCK_POS);\n safeState.lock();\n}\n\nvoid unlock() {\n lockServo.write(SERVO_UNLOCK_POS);\n}\n\nvoid showStartupMessage() {\n lcd.setCursor(4, 0);\n lcd.print(\"Welcome!\");\n delay(1000);\n\n lcd.setCursor(0, 2);\n String message = \"ArduinoSafe v1.0\";\n for (byte i = 0; i < message.length(); i++) {\n lcd.print(message[i]);\n delay(100);\n }\n delay(500);\n}\n\nString inputSecretCode() {\n lcd.setCursor(5, 1);\n lcd.print(\"[____]\");\n lcd.setCursor(6, 1);\n String result = \"\";\n while (result.length() < 4) {\n char key = keypad.getKey();\n if (key >= '0' && key <= '9') {\n lcd.print('*');\n result += key;\n }\n }\n return result;\n}\n\nvoid showWaitScreen(int delayMillis) {\n lcd.setCursor(2, 1);\n lcd.print(\"[..........]\");\n lcd.setCursor(3, 1);\n for (byte i = 0; i < 10; i++) {\n delay(delayMillis);\n lcd.print(\"=\");\n }\n}\n\nbool setNewCode() {\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.print(\"Enter new code:\");\n String newCode = inputSecretCode();\n\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.print(\"Confirm new code\");\n String confirmCode = inputSecretCode();\n\n if (newCode.equals(confirmCode)) {\n safeState.setCode(newCode);\n return true;\n } else {\n lcd.clear();\n lcd.setCursor(1, 0);\n lcd.print(\"Code mismatch\");\n lcd.setCursor(0, 1);\n lcd.print(\"Safe not locked!\");\n delay(2000);\n return false;\n }\n}\n\nvoid showUnlockMessage() {\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.write(ICON_UNLOCKED_CHAR);\n lcd.setCursor(4, 0);\n lcd.print(\"Unlocked!\");\n lcd.setCursor(15, 0);\n lcd.write(ICON_UNLOCKED_CHAR);\n delay(1000);\n}\n\nvoid safeUnlockedLogic() {\n lcd.clear();\n\n lcd.setCursor(0, 0);\n lcd.write(ICON_UNLOCKED_CHAR);\n lcd.setCursor(2, 0);\n lcd.print(\" # to lock\");\n lcd.setCursor(15, 0);\n lcd.write(ICON_UNLOCKED_CHAR);\n\n bool newCodeNeeded = true;\n\n if (safeState.hasCode()) {\n lcd.setCursor(0, 1);\n lcd.print(\" A = new code\");\n newCodeNeeded = false;\n }\n\n auto key = keypad.getKey();\n while (key != 'A' && key != '#') {\n key = keypad.getKey();\n }\n\n bool readyToLock = true;\n if (key == 'A' || newCodeNeeded) {\n readyToLock = setNewCode();\n }\n\n if (readyToLock) {\n lcd.clear();\n lcd.setCursor(5, 0);\n lcd.write(ICON_UNLOCKED_CHAR);\n lcd.print(\" \");\n lcd.write(ICON_RIGHT_ARROW);\n lcd.print(\" \");\n lcd.write(ICON_LOCKED_CHAR);\n\n safeState.lock();\n lock();\n showWaitScreen(100);\n }\n}\n\nvoid safeLockedLogic() {\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.write(ICON_LOCKED_CHAR);\n lcd.print(\" Safe Locked! \");\n lcd.write(ICON_LOCKED_CHAR);\n\n String userCode = inputSecretCode();\n bool unlockedSuccessfully = safeState.unlock(userCode);\n showWaitScreen(200);\n\n if (unlockedSuccessfully) {\n showUnlockMessage();\n unlock();\n } else {\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.print(\"Access Denied!\");\n showWaitScreen(1000);\n }\n}\n\nvoid setup() {\n lcd.begin(16, 2);\n init_icons(lcd);\n\n lockServo.attach(SERVO_PIN);\n\n /* Make sure the physical lock is sync with the EEPROM state */\n Serial.begin(115200);\n if (safeState.locked()) {\n lock();\n } else {\n unlock();\n }\n\n showStartupMessage();\n}\n\nvoid loop() {\n if (safeState.locked()) {\n safeLockedLogic();\n } else {\n safeUnlockedLogic();\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"id\": \"uno\", \"type\": \"wokwi-arduino-uno\", \"top\": 200, \"left\": 20 },\n {\n \"id\": \"keypad\",\n \"type\": \"wokwi-membrane-keypad\",\n \"left\": 360,\n \"top\": 140\n },\n {\n \"id\": \"servo\",\n \"type\": \"wokwi-servo\",\n \"left\": 400,\n \"top\": 20,\n \"attrs\": { \"hornColor\": \"black\" }\n },\n { \"id\": \"lcd\", \"type\": \"wokwi-lcd1602\", \"top\": 8, \"left\": 20 },\n {\n \"id\": \"r1\",\n \"type\": \"wokwi-resistor\",\n \"top\": 140,\n \"left\": 220,\n \"attrs\": { \"value\": \"220\" }\n }\n ],\n \"connections\": [\n [\"uno:GND.1\", \"lcd:VSS\", \"black\", [\"v-51\", \"*\", \"h0\", \"v18\"]],\n [\"uno:GND.1\", \"lcd:K\", \"black\", [\"v-51\", \"*\", \"h0\", \"v18\"]],\n [\"uno:GND.1\", \"lcd:RW\", \"black\", [\"v-51\", \"*\", \"h0\", \"v18\"]],\n [\"uno:5V\", \"lcd:VDD\", \"red\", [\"v16\", \"h-16\"]],\n [\"uno:5V\", \"r1:2\", \"red\", [\"v16\", \"h-118\", \"v-244\", \"h50\"]],\n [\"r1:1\", \"lcd:A\", \"pink\", []],\n [\"uno:12\", \"lcd:RS\", \"blue\", [\"v-16\", \"*\", \"h0\", \"v20\"]],\n [\"uno:11\", \"lcd:E\", \"purple\", [\"v-20\", \"*\", \"h0\", \"v20\"]],\n [\"uno:10\", \"lcd:D4\", \"green\", [\"v-24\", \"*\", \"h0\", \"v20\"]],\n [\"uno:9\", \"lcd:D5\", \"brown\", [\"v-28\", \"*\", \"h0\", \"v20\"]],\n [\"uno:8\", \"lcd:D6\", \"gold\", [\"v-32\", \"*\", \"h0\", \"v20\"]],\n [\"uno:7\", \"lcd:D7\", \"gray\", [\"v-36\", \"*\", \"h0\", \"v20\"]],\n [\"uno:6\", \"servo:PWM\", \"orange\", [\"v-40\", \"*\", \"h0\", \"h-52\"]],\n [\"uno:5V\", \"servo:V+\", \"red\", [\"v16\", \"h-118\", \"v-244\", \"*\", \"h-56\"]],\n [\"uno:GND.1\", \"servo:GND\", \"black\", [\"v-46\", \"*\", \"v88\", \"h-60\"]],\n [\"uno:A3\", \"keypad:C1\", \"brown\", [\"v116\", \"*\", \"h0\", \"v0\"]],\n [\"uno:A2\", \"keypad:C2\", \"gray\", [\"v120\", \"*\", \"h0\", \"v0\"]],\n [\"uno:A1\", \"keypad:C3\", \"orange\", [\"v124\", \"*\", \"h0\", \"v0\"]],\n [\"uno:A0\", \"keypad:C4\", \"pink\", [\"v128\", \"*\", \"h0\", \"v0\"]],\n [\"uno:5\", \"keypad:R1\", \"blue\", [\"v-34\", \"h96\", \"*\", \"v12\"]],\n [\"uno:4\", \"keypad:R2\", \"green\", [\"v-30\", \"h80\", \"*\", \"v16\"]],\n [\"uno:3\", \"keypad:R3\", \"purple\", [\"v-26\", \"h64\", \"*\", \"v20\"]],\n [\"uno:2\", \"keypad:R4\", \"gold\", [\"v-22\", \"h48\", \"*\", \"v24\"]]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for nano pong", + "input": "/*\n A simple Pong game.\n https://notabug.org/Maverick/WokwiPong\n \n Based on Arduino Pong by eholk\n https://github.com/eholk/Arduino-Pong\n*/\n\n#include \n#include \n#include \n#include \n\n#define UP_BUTTON 2\n#define DOWN_BUTTON 3\n\nconst unsigned long PADDLE_RATE = 64;\nconst unsigned long BALL_RATE = 16;\nconst uint8_t PADDLE_HEIGHT = 12;\nconst uint8_t SCORE_LIMIT = 9;\n\nAdafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);\n\nbool game_over, win;\n\nuint8_t player_score, mcu_score;\nuint8_t ball_x = 53, ball_y = 26;\nuint8_t ball_dir_x = 1, ball_dir_y = 1;\n\nunsigned long ball_update;\nunsigned long paddle_update;\n\nconst uint8_t MCU_X = 12;\nuint8_t mcu_y = 16;\n\nconst uint8_t PLAYER_X = 115;\nuint8_t player_y = 16;\n\nvoid setup() \n{\n display.begin(SSD1306_SWITCHCAPVCC, 0x3C);\n\n // Display the splash screen (we're legally required to do so)\n display.display();\n unsigned long start = millis();\n\n pinMode(UP_BUTTON, INPUT_PULLUP);\n pinMode(DOWN_BUTTON, INPUT_PULLUP);\n\n display.clearDisplay();\n drawCourt();\n\n while(millis() - start < 2000);\n\n display.display();\n\n ball_update = millis();\n paddle_update = ball_update;\n}\n\nvoid loop() \n{\n bool update_needed = false;\n unsigned long time = millis();\n\n static bool up_state = false;\n static bool down_state = false;\n \n up_state |= (digitalRead(UP_BUTTON) == LOW);\n down_state |= (digitalRead(DOWN_BUTTON) == LOW);\n\n if(time > ball_update) \n {\n uint8_t new_x = ball_x + ball_dir_x;\n uint8_t new_y = ball_y + ball_dir_y;\n\n // Check if we hit the vertical walls\n if(new_x == 0 || new_x == 127) \n {\n ball_dir_x = -ball_dir_x;\n new_x += ball_dir_x + ball_dir_x;\n\n if (new_x < 64)\n {\n player_scoreTone();\n player_score++;\n }\n else\n {\n mcu_scoreTone();\n mcu_score++;\n }\n\n if (player_score == SCORE_LIMIT || mcu_score == SCORE_LIMIT)\n {\n win = player_score > mcu_score;\n game_over = true;\n }\n }\n\n // Check if we hit the horizontal walls.\n if(new_y == 0 || new_y == 53) \n {\n wallTone();\n ball_dir_y = -ball_dir_y;\n new_y += ball_dir_y + ball_dir_y;\n }\n\n // Check if we hit the CPU paddle\n if(new_x == MCU_X && new_y >= mcu_y && new_y <= mcu_y + PADDLE_HEIGHT) \n {\n mcuPaddleTone();\n ball_dir_x = -ball_dir_x;\n new_x += ball_dir_x + ball_dir_x;\n }\n\n // Check if we hit the player paddle\n if(new_x == PLAYER_X && new_y >= player_y && new_y <= player_y + PADDLE_HEIGHT)\n {\n playerPaddleTone();\n ball_dir_x = -ball_dir_x;\n new_x += ball_dir_x + ball_dir_x;\n }\n\n display.drawPixel(ball_x, ball_y, BLACK);\n display.drawPixel(new_x, new_y, WHITE);\n ball_x = new_x;\n ball_y = new_y;\n\n ball_update += BALL_RATE;\n\n update_needed = true;\n }\n\n if(time > paddle_update) \n {\n paddle_update += PADDLE_RATE;\n\n // CPU paddle\n display.drawFastVLine(MCU_X, mcu_y, PADDLE_HEIGHT, BLACK);\n const uint8_t half_paddle = PADDLE_HEIGHT >> 1;\n\n if(mcu_y + half_paddle > ball_y)\n {\n int8_t dir = ball_x > MCU_X ? -1 : 1;\n mcu_y += dir;\n }\n\n if(mcu_y + half_paddle < ball_y)\n {\n int8_t dir = ball_x > MCU_X ? 1 : -1;\n mcu_y += dir;\n }\n\n if(mcu_y < 1) \n {\n mcu_y = 1;\n }\n\n if(mcu_y + PADDLE_HEIGHT > 53)\n {\n mcu_y = 53 - PADDLE_HEIGHT;\n }\n\n // Player paddle\n display.drawFastVLine(MCU_X, mcu_y, PADDLE_HEIGHT, WHITE);\n display.drawFastVLine(PLAYER_X, player_y, PADDLE_HEIGHT, BLACK);\n\n if(up_state) \n {\n player_y -= 1;\n }\n\n if(down_state) \n {\n player_y += 1;\n }\n\n up_state = down_state = false;\n\n if(player_y < 1) \n {\n player_y = 1;\n }\n\n if(player_y + PADDLE_HEIGHT > 53) \n {\n player_y = 53 - PADDLE_HEIGHT;\n }\n\n display.drawFastVLine(PLAYER_X, player_y, PADDLE_HEIGHT, WHITE);\n\n update_needed = true;\n }\n\n if(update_needed)\n {\n if (game_over)\n {\n const char* text = win ? \"YOU WIN!!\" : \"YOU LOSE!\";\n display.clearDisplay();\n display.setCursor(40, 28);\n display.print(text);\n display.display();\n\n delay(5000);\n\n display.clearDisplay();\n ball_x = 53;\n ball_y = 26;\n ball_dir_x = 1;\n ball_dir_y = 1;\n mcu_y = 16;\n player_y = 16;\n mcu_score = 0;\n player_score = 0;\n game_over = false;\n drawCourt();\n }\n\n display.setTextColor(WHITE, BLACK);\n display.setCursor(0, 56);\n display.print(mcu_score);\n display.setCursor(122, 56);\n display.print(player_score);\n display.display();\n }\n}\n\nvoid playerPaddleTone()\n{\n tone(11, 250, 25);\n delay(25);\n noTone(11);\n}\n\nvoid mcuPaddleTone()\n{\n tone(11, 225, 25);\n delay(25);\n noTone(11);\n}\n\nvoid wallTone()\n{\n tone(11, 200, 25);\n delay(25);\n noTone(11);\n}\n\nvoid player_scoreTone()\n{\n tone(11, 200, 25);\n delay(50);\n noTone(11);\n delay(25);\n tone(11, 250, 25);\n delay(25);\n noTone(11);\n}\n\nvoid mcu_scoreTone()\n{\n tone(11, 250, 25);\n delay(25);\n noTone(11);\n delay(25);\n tone(11, 200, 25);\n delay(25);\n noTone(11);\n}\n\nvoid drawCourt() \n{\n display.drawRect(0, 0, 128, 54, WHITE);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Maverick\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-nano\", \"id\": \"nano\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"board-ssd1306\", \"id\": \"oled1\", \"top\": 89.5, \"left\": 19.05, \"attrs\": {} },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": 87.7,\n \"left\": 136.24,\n \"attrs\": { \"color\": \"green\", \"key\": \"ArrowUp\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn2\",\n \"top\": 134.3,\n \"left\": 135.54,\n \"attrs\": { \"color\": \"green\", \"key\": \"ArrowDown\" }\n },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -103.22,\n \"left\": 59.98,\n \"attrs\": { \"volume\": \"0.1\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": -22.03,\n \"left\": 29.82,\n \"attrs\": { \"value\": \"1000\" }\n }\n ],\n \"connections\": [\n [ \"nano:A4\", \"oled1:SDA\", \"gold\", [ \"v0\" ] ],\n [ \"oled1:SCL\", \"nano:A5\", \"cyan\", [ \"v-20.36\", \"h20.38\" ] ],\n [ \"oled1:VCC\", \"nano:3.3V\", \"red\", [ \"v-20.07\", \"h-37.37\" ] ],\n [ \"oled1:GND\", \"nano:GND.1\", \"black\", [ \"v-12.82\", \"h87.28\" ] ],\n [ \"btn1:2.l\", \"btn2:2.l\", \"black\", [ \"h-6.06\", \"v46.8\" ] ],\n [ \"btn1:2.l\", \"nano:GND.1\", \"black\", [ \"h-6.51\", \"v-36.84\", \"h14.77\" ] ],\n [ \"btn1:1.r\", \"nano:2\", \"black\", [ \"h13.06\", \"v-114.15\", \"h-100.6\" ] ],\n [ \"btn2:1.r\", \"nano:3\", \"black\", [ \"v-0.29\", \"h14.22\", \"v-160.46\", \"h-110.66\" ] ],\n [ \"bz1:2\", \"r1:2\", \"red\", [ \"v0\" ] ],\n [ \"r1:1\", \"nano:11\", \"red\", [ \"h-0.55\", \"v50.86\" ] ],\n [ \"bz1:1\", \"nano:GND.2\", \"black\", [ \"h34.91\", \"v64.63\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for touch lcd breakout game", + "input": "#include \n#include \n#include \n#include \"ourOSObj.h\"\n\nourOSObj ourOS;\n\nvoid setup() {\n \n Serial.begin(57600); // Fire up serial for debugging.\n if (!initScreen(ADAFRUIT_1947,ADA_1947_SHIELD_CS,PORTRAIT)) { // Init screen.\n Serial.println(\"NO SCREEN!\"); // Screen init failed. Tell user.\n Serial.flush(); // Make sure the message gets out.\n while(true); // Lock the process here.\n }\n if (!SD.begin(ADA_1947_SHIELD_SDCS)) { // With icons, we now MUST have an SD card.\n Serial.println(\"NO SD CARD!\"); // Tell user we have no SD card.\n Serial.flush(); // Make sure the message gets out.\n while(true); // Lock the process here.\n }\n ourEventMgr.begin(); // Startup our event manager.\n ourOS.begin(); // Boot OS manager.\n nextPanel = breakoutApp; // <<-- URISH LOOK HERE!!\n}\n\n\nvoid loop() { // During loop..\n \n idle(); // Idlers get their time.\n ourOS.loop(); // ourOS gets time to pass on to the current panel.\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Jim Lee\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-arduino-mega\",\n \"id\": \"mega\",\n \"top\": 272.86,\n \"left\": -34.52,\n \"attrs\": { \"__fakeRamSize\": \"65000\" }\n },\n {\n \"type\": \"board-ili9341-cap-touch\",\n \"id\": \"lcd1\",\n \"top\": -149.52,\n \"left\": 75.06,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-microsd-card\",\n \"id\": \"sd1\",\n \"top\": 39.23,\n \"left\": 395.41,\n \"rotate\": 90,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": 481.7,\n \"left\": 153.47,\n \"attrs\": { \"volume\": \"0.025\" }\n }\n ],\n \"connections\": [\n [ \"mega:GND.1\", \"lcd1:GND\", \"black\", [ \"v-53\", \"h-5\" ] ],\n [ \"mega:52\", \"lcd1:SCK\", \"white\", [ \"v-54\", \"h19\" ] ],\n [ \"mega:50\", \"lcd1:MISO\", \"green\", [ \"v-43\", \"h35\" ] ],\n [ \"mega:51\", \"lcd1:MOSI\", \"blue\", [ \"v0\", \"h-197\", \"v-226\", \"h112\" ] ],\n [ \"mega:53\", \"lcd1:D/C\", \"yellow\", [ \"v-67\", \"h-28\" ] ],\n [ \"mega:5V\", \"lcd1:VCC\", \"red\", [ \"v26\", \"h-197\", \"v-226\", \"h112\" ] ],\n [ \"mega:10\", \"lcd1:CS\", \"red\", [ \"v-90\", \"h-31\" ] ],\n [ \"mega:20\", \"lcd1:SDA\", \"blue\", [ \"v24\" ] ],\n [ \"mega:52\", \"sd1:SCK\", \"white\", [ \"v-54\", \"h19\" ] ],\n [ \"mega:50\", \"sd1:DO\", \"green\", [ \"v-43\", \"h35\" ] ],\n [ \"mega:53\", \"sd1:CD\", \"yellow\", [ \"v-67\", \"h-28\" ] ],\n [ \"mega:4\", \"sd1:CS\", \"green\", [ \"v-87\", \"h63\" ] ],\n [ \"mega:5V\", \"sd1:VCC\", \"red\", [ \"v26.06\", \"h273\", \"v-325.06\", \"h27.3\" ] ],\n [ \"mega:GND.1\", \"sd1:GND\", \"black\", [ \"v-53\", \"h152\" ] ],\n [ \"mega:51\", \"sd1:DI\", \"blue\", [ \"v-2.49\", \"h31.94\", \"v-286.49\", \"h50.95\" ] ],\n [ \"mega:21\", \"lcd1:SCL\", \"white\", [ \"v-120.21\", \"h-4.54\" ] ],\n [ \"mega:GND.2\", \"bz1:1\", \"black\", [ \"v0\" ] ],\n [ \"mega:14\", \"bz1:2\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for dino game", + "input": "// A simple T-rex Run game based on the 30DLIS kit\n// Developed by Ishani and Arijit Sengupta\n// Required libraries\n#include \n#include \"TM1637Display.h\"\n\n// HW Pins required\n#define SW 3 // RotaryEncoder SW Pin\n#define DT 4 // RotaryEncoder DT Pin\n#define CLK 2 // RotaryEncoder CLK Pin\n\n// Define the display connections pins:\n#define DCLK 6\n#define DIO 5\n\n// pin 10 drives the buzzer\n#define buzzer 10\n\n// In Addition, this sketch uses the I2C Pins for the U8G Panel\n// A1+A2\n\n// Create display object of type TM1637Display\n// The display shows the current score\nTM1637Display OurDisplay = TM1637Display(DCLK, DIO);\n\n// Create array that turns all segments off:\nconst uint8_t blank[] = {0x00, 0x00, 0x00, 0x00}; // 0xff is a hexidecimal number whose binary\n// representation is all zeros\n\n// Create the oled display object - this shows gameplay\n// and welcome/win/loss messages\n\nU8GLIB_SH1106_128X64 My_u8g_Panel(U8G_I2C_OPT_NONE); // I2C / TWI\n\n/*\n For documentation on u8glib functions:\n https://github.com/olikraus/u8glib/wiki/userreference\n*/\n\n// Sounds we use for the hit effects\n#define jumpSound 700\n#define blahSound 125\n#define speedSound 1000\n#define DBOUNCE 180\n\n// Game states\n#define gameStart 0\n#define gameEnd 1\n#define gamePlaying 2\n\nvolatile int gameStatus = gameStart;\n\n// PRE-SAVED BITMAP CONSTANTS\n//20 x 21\nstatic unsigned char dinoJump [] U8G_PROGMEM = {\n 0x00, 0xFC, 0x07, 0x00, 0xFE, 0x07, 0x00, 0xEE, 0x0F, 0x00, 0xFE, 0x0F,\n 0x00, 0xFE, 0x0F, 0x00, 0xFE, 0x0F, 0x00, 0xFE, 0x07, 0x06, 0xFF, 0x03,\n 0xC3, 0xFF, 0x00, 0xE7, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00,\n 0xFF, 0x3F, 0x00, 0xFE, 0x3F, 0x00, 0xFC, 0x1F, 0x00, 0xF8, 0x1F, 0x00,\n 0xF0, 0x1F, 0x00, 0xF0, 0x0E, 0x00, 0x60, 0x0E, 0x00, 0xE0, 0x0E, 0x00,\n 0xE0, 0x1E, 0x00,\n};\n//20 x 21\nstatic unsigned char dinoLeft [] U8G_PROGMEM = {\n 0x00, 0xFC, 0x07, 0x00, 0xFE, 0x07, 0x00, 0xEE, 0x0F, 0x00, 0xFE, 0x0F,\n 0x00, 0xFE, 0x0F, 0x00, 0x7E, 0x08, 0x00, 0x7E, 0x00, 0x06, 0xFF, 0x03,\n 0x87, 0x3F, 0x00, 0xE7, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00,\n 0xFF, 0x3F, 0x00, 0xFE, 0x3F, 0x00, 0xFC, 0x1F, 0x00, 0xF8, 0x1F, 0x00,\n 0xF0, 0x1F, 0x00, 0xE0, 0x1E, 0x00, 0x60, 0x00, 0x00, 0xE0, 0x00, 0x00,\n 0xE0, 0x00, 0x00,\n};\n//20 x 21\nstatic unsigned char dinoRight [] U8G_PROGMEM = {\n 0x00, 0xFC, 0x07, 0x00, 0xEE, 0x07, 0x00, 0xE6, 0x0F, 0x00, 0xFE, 0x0F,\n 0x00, 0xFE, 0x0F, 0x00, 0xFE, 0x0F, 0x00, 0x7C, 0x00, 0x06, 0xFF, 0x03,\n 0xC3, 0xFF, 0x00, 0xE7, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00,\n 0xFF, 0x3F, 0x00, 0xFE, 0x3F, 0x00, 0xFC, 0x1F, 0x00, 0xF8, 0x1F, 0x00,\n 0xF0, 0x1F, 0x00, 0xF0, 0x0F, 0x00, 0xE0, 0x0E, 0x00, 0x00, 0x0E, 0x00,\n 0x00, 0x1E, 0x00,\n};\n//shape 0: 39 x 12\nstatic unsigned char cloud [] U8G_PROGMEM = {\n 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xBE, 0x03, 0x00, 0x00, 0x00,\n 0x03, 0x06, 0x00, 0x00, 0x80, 0x01, 0x04, 0x00, 0x00, 0x40, 0x00, 0x1C,\n 0x00, 0x00, 0x40, 0x00, 0xE4, 0x03, 0x00, 0x18, 0x00, 0x00, 0x02, 0xE0,\n 0x0F, 0x00, 0x00, 0x0E, 0x30, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\n 0x00, 0x20, 0x12, 0x00, 0x00, 0x00, 0x40, 0x03, 0xFF, 0xFF, 0xFF, 0x7F,\n};\n//shape 1: 10 x 20\nstatic unsigned char oneCactus [] U8G_PROGMEM = {\n 0x30, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x01, 0xFB, 0x03,\n 0xFF, 0x03, 0xFF, 0x03, 0xFF, 0x03, 0xFF, 0x03, 0xFF, 0x03, 0xFF, 0x01,\n 0xFE, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00,\n 0x78, 0x00, 0x00, 0x00,\n};\n//shape 2: 20 x 20\nstatic unsigned char twoCactus [] U8G_PROGMEM = {\n 0x30, 0xC0, 0x00, 0x38, 0xE0, 0x00, 0x38, 0xE8, 0x00, 0x38, 0xEC, 0x00,\n 0x38, 0xED, 0x04, 0xBB, 0xED, 0x0E, 0xBB, 0xED, 0x0E, 0xBB, 0xFD, 0x0E,\n 0xBB, 0xFD, 0x0E, 0xBB, 0xF9, 0x0E, 0xFF, 0xF1, 0x0F, 0xFF, 0xE0, 0x07,\n 0x7E, 0xE0, 0x01, 0x38, 0xE0, 0x00, 0x38, 0xE0, 0x00, 0x38, 0xE0, 0x00,\n 0x38, 0xE0, 0x00, 0x38, 0xE0, 0x00, 0x38, 0xE0, 0x00, 0x00, 0x00, 0x00,\n};\n\n//shape 3: 20 x 20\nstatic unsigned char threeCactus [] U8G_PROGMEM = {\n 0x00, 0xC0, 0x00, 0x18, 0xC0, 0x01, 0x18, 0xC0, 0x01, 0x58, 0xD8, 0x01,\n 0x58, 0xFC, 0x01, 0x58, 0xFC, 0x0F, 0x78, 0xDC, 0x0F, 0x7F, 0xFC, 0x0F,\n 0x3B, 0xFD, 0x0D, 0x1B, 0xF9, 0x0C, 0x5B, 0xF5, 0x0F, 0x5B, 0xC5, 0x07,\n 0x5F, 0xE7, 0x03, 0xDE, 0xE7, 0x01, 0xD8, 0xC3, 0x01, 0x98, 0xC1, 0x01,\n 0x18, 0xC1, 0x01, 0x18, 0xC1, 0x01, 0x18, 0xE1, 0x01, 0x00, 0x00, 0x00,\n};\n//shape 4: 6 x 12\nstatic unsigned char oneCactusSmall [] U8G_PROGMEM = {\n 0x0C, 0x0C, 0x3C, 0x3D, 0x2D, 0x3D, 0x1D, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C,\n};\n//shape 5: 12 x 12\nstatic unsigned char twoCactusSmall [] U8G_PROGMEM = {\n 0x0C, 0x03, 0x0C, 0x03, 0x6C, 0x0B, 0x6D, 0x0B, 0x6D, 0x0B, 0xBD, 0x0B,\n 0x1F, 0x0F, 0x0E, 0x03, 0x0C, 0x03, 0x0C, 0x03, 0x0C, 0x03, 0x0C, 0x03,\n};\n//shape 6: 17 x 12\nstatic unsigned char threeCactusSmall [] U8G_PROGMEM = {\n 0x04, 0x41, 0x00, 0x0C, 0x61, 0x00, 0xFC, 0x79, 0x01, 0xFD, 0x7D, 0x01,\n 0x7D, 0x6D, 0x01, 0x7D, 0x7D, 0x01, 0xCF, 0xE5, 0x01, 0xCE, 0x67, 0x00,\n 0x8C, 0x67, 0x00, 0x0C, 0x63, 0x00, 0x0C, 0x61, 0x00, 0x0C, 0x61, 0x00,\n};\n\nstatic unsigned char dinoBlah [] U8G_PROGMEM = {\n 0x00, 0xFC, 0x07, 0x00, 0xFE, 0x07, 0x00, 0xC6, 0x0F, 0x00, 0xC6, 0x0F,\n 0x00, 0xCE, 0x0F, 0x00, 0xFE, 0x0F, 0x00, 0xFE, 0x0F, 0x06, 0xFF, 0x03,\n 0x87, 0x7F, 0x00, 0xE7, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00,\n 0xFF, 0x3F, 0x00, 0xFE, 0x3F, 0x00, 0xFC, 0x1F, 0x00, 0xF8, 0x1F, 0x00,\n 0xF0, 0x1F, 0x00, 0xF0, 0x0E, 0x00, 0x60, 0x0E, 0x00, 0x60, 0x0E, 0x00,\n 0xE0, 0x1E, 0x00,\n};\n\nstatic unsigned char gameOver [] U8G_PROGMEM = {\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0xF8, 0x01, 0x02, 0x0C, 0x0C, 0x3E, 0x00, 0x78, 0x60,\n 0x30, 0x7C, 0xF0, 0x01, 0x0C, 0x01, 0x07, 0x14, 0x0A, 0x02, 0x00, 0x84,\n 0x40, 0x10, 0x04, 0x10, 0x02, 0x04, 0x00, 0x05, 0x14, 0x0A, 0x02, 0x00,\n 0x02, 0x41, 0x10, 0x04, 0x10, 0x02, 0x04, 0x00, 0x05, 0x14, 0x0A, 0x02,\n 0x00, 0x02, 0xC1, 0x18, 0x04, 0x10, 0x02, 0xC4, 0x81, 0x0D, 0x34, 0x0B,\n 0x3E, 0x00, 0x02, 0x81, 0x08, 0x7C, 0xF0, 0x01, 0x04, 0x81, 0x08, 0x24,\n 0x09, 0x02, 0x00, 0x02, 0x81, 0x0D, 0x04, 0x10, 0x01, 0x04, 0x81, 0x0F,\n 0x64, 0x09, 0x02, 0x00, 0x02, 0x01, 0x05, 0x04, 0x10, 0x02, 0x0C, 0xC1,\n 0x18, 0xC4, 0x08, 0x02, 0x00, 0x84, 0x00, 0x05, 0x04, 0x10, 0x02, 0xF8,\n 0x41, 0x10, 0xC4, 0x08, 0x3E, 0x00, 0x78, 0x00, 0x07, 0x7C, 0x10, 0x02,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00,\n};\n\n\n// Other Game attributes\n\n// various variables\nint currentStateCLK;\nint lastStateCLK;\nint MyScore = 0;\nint dinoMove = 0;\nvolatile int jumping = 0;\nint cloudx = 128;\nint obstacles [2] = {1, 4};\nint obstaclex [2] = {128, 200};\nint speed = 8;\nunsigned long startTime = millis(), curTime;\nint lastBeep = 0;\n\n// Display the score on the 7seg display\nvoid ShowScore () {\n if (gameStatus == gamePlaying) {\n curTime = millis ();\n MyScore = (curTime - startTime) * speed / 1000;\n OurDisplay.showNumberDecEx(MyScore);\n if (MyScore / 100 > lastBeep) {\n tone (buzzer, 1000, 100);\n delay (150);\n tone (buzzer, 1250, 100);\n lastBeep = MyScore / 100;\n }\n }\n}\n\n\nvoid StartStopGame () {\n static unsigned long last_interrupt = 0;\n if (millis() - last_interrupt > DBOUNCE) {\n if (gameStatus == gamePlaying) {\n if (jumping == 0) {\n jumping = 1;\n tone (buzzer, jumpSound, 100);\n }\n }\n else if (gameStatus == gameStart) gameStatus = gamePlaying;\n else gameStatus = gameStart;\n }\n last_interrupt = millis(); //note the last time the ISR was called\n\n}\n\nvoid resetGame () {\n MyScore = 0;\n startTime = millis();\n obstaclex[0] = 128;\n obstaclex [1] = 200;\n dinoMove = 0;\n}\n\nvoid setup() {\n OurDisplay.setBrightness(7);\n OurDisplay.clear();\n resetGame();\n ShowScore ();\n pinMode(CLK, INPUT);\n pinMode(DT, INPUT);\n pinMode(SW, INPUT_PULLUP);\n pinMode(buzzer, OUTPUT);\n attachInterrupt(digitalPinToInterrupt(SW), StartStopGame, FALLING);\n}\n\n// ************************************************\nvoid loop(void) {\n ShowScore();\n My_u8g_Panel.firstPage();\n do {\n draw();\n } while ( My_u8g_Panel.nextPage() );\n if (gameStatus == gamePlaying) {\n moveDino();\n moveCloud();\n moveObstacles();\n }\n}\n\nvoid moveDino () {\n if (jumping == 0) dinoMove = (dinoMove + 1) % 3;\n else {\n if (jumping == 1) {\n dinoMove = dinoMove + 8;\n if (dinoMove > 32) jumping = 2;\n } else {\n dinoMove = dinoMove - 8;\n if (dinoMove < 8) {\n jumping = 0;\n dinoMove = 0;\n }\n }\n }\n checkCollision ();\n}\n\nvoid moveCloud () {\n cloudx --;\n if (cloudx < -38) cloudx = 128;\n}\n\nvoid moveObstacles() {\n int obx = obstaclex [0];\n obx = obx - speed;\n if (obx < -20) {\n obstaclex[0] = obstaclex[1];\n obstaclex[1] = obstaclex[0] + random(80, 125);\n obstacles[0] = obstacles[1];\n obstacles[1] = random (1, 6);\n }\n else {\n obstaclex[0] = obx;\n obstaclex[1] -= speed;\n }\n\n}\n// ************************************************\n\nvoid draw(void) {\n u8g_prepare();\n if (gameStatus == gamePlaying) {\n drawDino ();\n drawShape (0, cloudx);\n drawObsticles ();\n }\n else if (gameStatus == gameStart) {\n My_u8g_Panel.drawStr( 0, 10, \"Welcome to\");\n My_u8g_Panel.drawStr( 10, 30, \"Dino!!\");\n My_u8g_Panel.drawStr( 0, 50, \"Push to begin\");\n resetGame();\n ShowScore();\n }\n else {\n My_u8g_Panel.drawXBMP( 14, 12, 100, 15, gameOver);\n drawDino ();\n drawShape (0, cloudx);\n drawObsticles ();\n }\n\n}\n\n\nvoid drawDino (void) {\n if (gameStatus == gameEnd) {\n My_u8g_Panel.drawXBMP( 0, 43 - dinoMove, 20, 21, dinoBlah);\n return;\n }\n switch (dinoMove) {\n case -1: My_u8g_Panel.drawXBMP( 0, 43, 20, 21, dinoBlah); break;\n case 0: My_u8g_Panel.drawXBMP( 0, 43, 20, 21, dinoJump); break;\n case 1: My_u8g_Panel.drawXBMP( 0, 43, 20, 21, dinoLeft); break;\n case 2: My_u8g_Panel.drawXBMP( 0, 43, 20, 21, dinoRight); break;\n default: My_u8g_Panel.drawXBMP( 0, 43 - dinoMove, 20, 21, dinoJump); break;\n }\n}\n\nvoid drawShape (int shape, int x) {\n switch (shape) {\n case 0: My_u8g_Panel.drawXBMP( x, 5, 39, 12, cloud); break;\n case 1: My_u8g_Panel.drawXBMP( x, 44, 10, 20, oneCactus); break;\n case 2: My_u8g_Panel.drawXBMP( x, 44, 20, 20, twoCactus); break;\n case 3: My_u8g_Panel.drawXBMP( x, 44, 20, 20, threeCactus); break;\n case 4: My_u8g_Panel.drawXBMP( x, 52, 6, 12, oneCactusSmall); break;\n case 5: My_u8g_Panel.drawXBMP( x, 52, 12, 12, twoCactusSmall); break;\n case 6: My_u8g_Panel.drawXBMP( x, 52, 17, 12, threeCactusSmall); break;\n }\n}\n\nvoid checkCollision () {\n int obx = obstaclex [0];\n int obw, obh;\n\n switch (obstacles[0]) {\n case 0: obw = 39; obh = 10; break;\n case 1: obw = 10; obh = 20; break;\n case 2: obw = 17; obh = 20; break;\n case 3: obw = 17; obh = 20; break;\n case 4: obw = 6; obh = 12; break;\n case 5: obw = 12; obh = 12; break;\n case 6: obw = 17; obh = 12; break;\n }\n if (obx > 15 || obx + obw < 5 || dinoMove > obh - 3) {}\n else {\n gameStatus = gameEnd;\n tone (buzzer, 125, 100);\n delay(150);\n tone (buzzer, 125, 100);\n }\n}\nvoid drawObsticles () {\n drawShape (obstacles[0], obstaclex[0]);\n drawShape (obstacles[1], obstaclex[1]);\n}\nvoid u8g_prepare(void) {\n My_u8g_Panel.setFont(u8g_font_6x10);\n My_u8g_Panel.setFontRefHeightExtendedText();\n My_u8g_Panel.setDefaultForegroundColor();\n My_u8g_Panel.setFontPosTop();\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Ami Sung\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 90.93, \"left\": -190.84, \"attrs\": {} },\n { \"type\": \"board-ssd1306\", \"id\": \"oled1\", \"top\": 121.27, \"left\": 158.38, \"attrs\": {} },\n { \"type\": \"wokwi-ky-040\", \"id\": \"encoder1\", \"top\": 268.93, \"left\": 115.97, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -41.84,\n \"left\": 252.89,\n \"attrs\": { \"volume\": \"0.1\" }\n },\n {\n \"type\": \"wokwi-tm1637-7segment\",\n \"id\": \"sevseg1\",\n \"top\": -44.94,\n \"left\": 37.09,\n \"attrs\": { \"color\": \"red\" }\n }\n ],\n \"connections\": [\n [ \"sevseg1:VCC\", \"uno:5V\", \"red\", [ \"h29.56\", \"v70.22\", \"h-142.27\", \"v268.59\", \"h-125.71\" ] ],\n [ \"encoder1:VCC\", \"uno:5V\", \"red\", [ \"h21.09\", \"v71.64\", \"h-283.92\" ] ],\n [ \"oled1:VCC\", \"uno:5V\", \"red\", [ \"v-37.85\", \"h-100.73\", \"v260\", \"h-135.52\" ] ],\n [ \"sevseg1:GND\", \"uno:GND.1\", \"black\", [ \"h-1.1\", \"v38.55\", \"h-286.37\" ] ],\n [ \"bz1:1\", \"uno:GND.1\", \"black\", [ \"v16.61\", \"h-356.06\" ] ],\n [ \"oled1:GND\", \"uno:GND.3\", \"black\", [ \"v-22.52\", \"h-102.93\", \"v205.43\", \"h-95.66\" ] ],\n [ \"encoder1:GND\", \"uno:GND.2\", \"black\", [ \"h14.96\", \"v51.4\", \"h-263.68\" ] ],\n [ \"encoder1:SW\", \"uno:3\", \"gray\", [ \"h14.47\", \"v-73.42\", \"h-102.32\", \"v-157.92\", \"h-97.87\" ] ],\n [ \"encoder1:DT\", \"uno:4\", \"gold\", [ \"h5.58\", \"v-54.93\", \"h-100.09\", \"v-148.29\", \"h-110.47\" ] ],\n [ \"encoder1:CLK\", \"uno:2\", \"orange\", [ \"h-1.1\", \"v-35.79\", \"h-103.06\", \"v-143.84\" ] ],\n [ \"bz1:2\", \"uno:10\", \"purple\", [ \"v15.53\", \"h50.01\", \"v-147.54\", \"h-370.71\" ] ],\n [ \"sevseg1:DIO\", \"uno:5\", \"green\", [ \"h28.05\", \"v-57.18\", \"h-218.72\" ] ],\n [ \"sevseg1:CLK\", \"uno:6\", \"green\", [ \"h18.41\", \"v-56.48\", \"h-224.65\" ] ],\n [ \"oled1:SCL\", \"uno:A5\", \"blue\", [ \"v-34.37\", \"h57.64\", \"v303.38\", \"h-198.32\" ] ],\n [ \"oled1:SDA\", \"uno:A4\", \"green\", [ \"v-23.17\", \"h61.03\", \"v300.18\", \"h-229.18\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for Four LED blink series", + "input": "int led5=5;\nint led6=6;\nint led7=7;\nint led8=8;\n\nvoid setup() {\n pinMode(led5,OUTPUT);\n pinMode(led6,OUTPUT);\n pinMode(led7,OUTPUT);\n pinMode(led8,OUTPUT);\n Serial.begin(9600);\n}\n\nvoid loop() {\n digitalWrite(led5,HIGH);\n digitalWrite(led6,LOW);\n digitalWrite(led7,LOW);\n digitalWrite(led8,LOW);\n delay(500);\n digitalWrite(led5,LOW);\n digitalWrite(led6,HIGH);\n digitalWrite(led7,LOW);\n digitalWrite(led8,LOW);\n delay(500);\n digitalWrite(led5,LOW);\n digitalWrite(led6,LOW);\n digitalWrite(led7,HIGH);\n digitalWrite(led8, LOW);\n delay(500);\n digitalWrite(led5, LOW);\n digitalWrite(led6, LOW);\n digitalWrite(led7, LOW);\n digitalWrite(led8, HIGH);\n delay(500);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"salwa nafisya9.3\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 106.2, \"left\": 18.6, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -42, \"left\": 263, \"attrs\": { \"color\": \"red\" } },\n { \"type\": \"wokwi-led\", \"id\": \"led2\", \"top\": -42, \"left\": 157.4, \"attrs\": { \"color\": \"blue\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": -42,\n \"left\": 61.4,\n \"attrs\": { \"color\": \"purple\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led4\",\n \"top\": -42,\n \"left\": -34.6,\n \"attrs\": { \"color\": \"green\" }\n }\n ],\n \"connections\": [\n [ \"led1:A\", \"uno:8\", \"green\", [ \"v76.8\", \"h-96\" ] ],\n [ \"led2:A\", \"uno:7\", \"green\", [ \"v67.2\", \"h9.6\" ] ],\n [ \"led3:A\", \"uno:6\", \"green\", [ \"v57.6\", \"h124.8\" ] ],\n [ \"led4:A\", \"uno:5\", \"green\", [ \"v48\", \"h230.4\" ] ],\n [ \"led3:C\", \"uno:GND.1\", \"green\", [ \"v86.4\", \"h58\" ] ],\n [ \"led4:C\", \"uno:GND.1\", \"green\", [ \"v76.8\", \"h154\", \"v28.8\" ] ],\n [ \"led2:C\", \"uno:GND.1\", \"green\", [ \"v76.8\", \"h-38\" ] ],\n [ \"led1:C\", \"uno:GND.1\", \"green\", [ \"v86.4\", \"h-143.6\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for test Arduino", + "input": "int TIME_INTERVAL = 0;\n\nbool isReady = false;\n\n\nvoid setup() {\n // put your setup code here, to run once:\n pinMode(13, OUTPUT);\n}\n\n\nvoid loop() {\n // put your main code here, to run repeatedly:\n TIME_INTERVAL++;\n digitalWrite(13, LOW);\n\n if(TIME_INTERVAL == 500) {\n isReady = true;\n TIME_INTERVAL = 0;\n }\n else {\n return;\n }\n\n if(isReady == true) {\n digitalWrite(13, HIGH);\n isReady = false;\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0.6, \"left\": 9, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": -70.8,\n \"left\": 109.4,\n \"attrs\": { \"color\": \"red\" }\n }\n ],\n \"connections\": [ [ \"uno:13\", \"led1:C\", \"green\", [ \"v0\" ] ], [ \"led1:A\", \"uno:8\", \"green\", [ \"v0\" ] ] ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for SUP_LCD", + "input": "#include \n#include \"timer_System.h\"\n#include \"inps_manager.h\"\n#include \"asciitohex.h\"\n#define VIEW_MENU 1\n#define INC_MENU 2\n#define DEC_MENU 3\nconst int KEY_MENU = 7;\nconst int KEY_INC = 8;\nconst int KEY_DEC = 9;\nconst int DIGIT_1 = 6;\nconst int DIGIT_2 = 5;\nconst int DIGIT_3 = 4;const int DATA_SPI = 12;\nconst int CLOCK_SPI = 11;\nconst int LOAD_SPI = 10;\nuint8_t count = 16;\ntypedef union _MENU_DEVICE\n{\n\tuint8_t value;\n\tstruct\n\t{\n\t\tunsigned edit:2;\t\t \n unsigned param_sel:3;\t\t \t\n\t\tunsigned peram_edit:1;\t\n\t\tunsigned blinK_dsp:1;\t\t \n unsigned extend:1;\t\t \n\t}flags;\n}MENU_DEVICE;\nMENU_DEVICE info_menu;\nconst uint16_t thresoldLow[3] = {85, 125, 5};\nconst uint16_t thresoldHigh[3] = {115, 140, 300};\nuint16_t thresoldValue[3] = {100, 140, 20}; \nuint16_t paramToView[3] = {0};\nvoid checkInputKeys(void);\nvoid vProcessKeys(uint8_t sel);\nvoid decimal_to_bcd(uint16_t decimal); \nvoid SetTimer1()\n{\n cli(); //stop interrupts\n //set timer1 interrupt at 120Hz\n TCCR1A = 0;// set entire TCCR1A register to 0\n TCCR1B = 0;// same for TCCR1B\n TCNT1 = 0;//initialize counter value to 0\n // set compare match register for 60hz increments\n OCR1A = 10000; // = (16*10^6) / (120 * 8) - 1 (must be <65536) //60Hz 16683\n // turn on CTC mode\n TCCR1B |= (1 << WGM12);\n // Set CS10 and CS12 bits for 1024 prescaler\n //TCCR1B |= (1 << CS12) | (1 << CS10);\n // Set CS11 bit for 8 prescaler\n TCCR1B |= (1 << CS11);\n // enable timer compare interrupt\n TIMSK1 |= (1 << OCIE1A);\n sei(); //allow interrupts\n}\nISR(TIMER1_COMPA_vect)\n{\n flagTickBase = 1;\n TimersSys_Tick();\n inpManager_Refresh();\n}\nvoid setup() \n{\n SetTimer1();\n TimersSys_Init();\t\t // Inicializa la estructuras de los 4 timers del sistema, en el header de la libreria\n\tTimersSys_Start(0, 10); // Inicializa 0 de TimerSys, de calibraci\u00f3n\t100 ms\n TimersSys_Start(1, 25); // Inicializa 1 de TimersSys: 250ms (25 * Tick de TMR2(10ms)) \n\tTimersSys_Start(2, 3); // Inicializa 2 de TimersSys: 30ms (3 * Tick de TMR2(10ms)) \n\tTimersSys_Start(3, 50); // Inicializa 2 de TimersSys: 30ms (3 * Tick de TMR2(10ms)) \n inpsManager_Init();\n inpsManager_Cfg(0, KEY_MENU, INPUT_PULLUP);\n inpsManager_Cfg(1, KEY_INC, INPUT_PULLUP);\n inpsManager_Cfg(2, KEY_DEC, INPUT_PULLUP);\n Serial.begin(115200);\n // put your setup code here, to run once:\n /*pinMode(KEY_MENU, INPUT_PULLUP);\n pinMode(KEY_INC, INPUT_PULLUP);*/\n pinMode(DIGIT_1, OUTPUT);\n pinMode(DIGIT_2, OUTPUT);\n pinMode(DIGIT_3, OUTPUT); \n pinMode(LOAD_SPI, OUTPUT);\n pinMode(CLOCK_SPI, OUTPUT);\n pinMode(DATA_SPI, OUTPUT);\n digitalWrite(DIGIT_1, HIGH);\n digitalWrite(DIGIT_2, HIGH);\n digitalWrite(DIGIT_3, HIGH);\n info_menu.value = 0;\n}\nvoid loop() \n{\n if (TIMERSYS_CHECK_EVENT(0))\t\t\t// 100 ms\n\t{\n\t\tTIMERSYS_CLEAR_EVENT(0);\n checkInputKeys( );\n }\n //llevar esta a 50 ms\n if (TIMERSYS_CHECK_EVENT(1))\t\t\t// 250 ms\n\t{\n\t\tTIMERSYS_CLEAR_EVENT(1);\n }\n if (TIMERSYS_CHECK_EVENT(2))\t\t\t//30ms\n\t{\n\t\tTIMERSYS_CLEAR_EVENT(2);\n if(++count >= 3)\n {\n count = 0;\n } \n if(info_menu.flags.edit == 0)\n {\n decimal_to_bcd(120);\n digitSelect(count, SevenSegmentASCII[paramToView[count]]);\n }\n else if(info_menu.flags.edit == 1)\n {\n digitSelect(count, MenutoDisplay[info_menu.flags.param_sel - 1][count]);\n }\n else if(info_menu.flags.edit == 2)\n {\n decimal_to_bcd(thresoldValue[info_menu.flags.param_sel - 1]);\n digitSelect(count, SevenSegmentASCII[paramToView[count]]);\n } \n }\n if (TIMERSYS_CHECK_EVENT(3))\t\t\t//500s\n {\n TIMERSYS_CLEAR_EVENT(3);\n if(info_menu.flags.blinK_dsp == 0)\n {\n info_menu.flags.blinK_dsp = 1; \n } \n else\n {\n info_menu.flags.blinK_dsp = 0;\n }\n }\n\n}\n\nvoid checkInputKeys( )\n{\n if(inpsInfo[0].b.change == 1)\n {\n inpsInfo[0].b.change = 0;\n if(!GET_INP_STATE(0))\n {\n vProcessKeys(VIEW_MENU);\n }\n }\n\n if(inpsInfo[1].b.change == 1)\n {\n inpsInfo[1].b.change = 0;\n if(!GET_INP_STATE(1))\n {\n vProcessKeys(INC_MENU);\n //Serial.println(\"INC\");\n }\n }\n\n if(inpsInfo[2].b.change == 1)\n {\n inpsInfo[2].b.change = 0;\n if(!GET_INP_STATE(2))\n {\n vProcessKeys(DEC_MENU);\n //Serial.println(\"DEC\");\n }\n }\n}\nvoid digitSelect(uint8_t select, uint8_t value)\n{\n digitalWrite(DIGIT_1, HIGH);\n digitalWrite(DIGIT_2, HIGH);\n digitalWrite(DIGIT_3, HIGH);\n if(info_menu.flags.blinK_dsp == 1 && info_menu.flags.edit == 2)\n {\n return;\n }\n digitalWrite(LOAD_SPI, LOW);\n shiftOut(DATA_SPI, CLOCK_SPI, MSBFIRST, value);\n digitalWrite(LOAD_SPI, HIGH); \n switch(select)\n {\n case 0:\n digitalWrite(DIGIT_3, LOW);\n break;\n case 1:\n digitalWrite(DIGIT_2, LOW);\n break;\n case 2:\n digitalWrite(DIGIT_1, LOW);\n break;\n default: \n return;\n } \n}\nvoid vProcessKeys(uint8_t sel)\n{\n if(sel == VIEW_MENU)\n {\n if(info_menu.flags.edit == 0)\n {\n info_menu.flags.edit = 1;\n info_menu.flags.param_sel = 1;\n }\n else if(info_menu.flags.edit == 1)\n {\n info_menu.flags.edit = 2;\n } \n else\n {\n info_menu.flags.edit = 0;\n }\n return;\n }\n\n if(sel == INC_MENU)\n {\n if(info_menu.flags.edit == 1)\n {\n if(++info_menu.flags.param_sel > 3)\n {\n info_menu.flags.param_sel = 0;\n info_menu.flags.edit = 0; \n }\n }\n else if(info_menu.flags.edit == 2)\n {\n if(++thresoldValue[info_menu.flags.param_sel -1] > thresoldHigh[info_menu.flags.param_sel -1])\n {\n thresoldValue[info_menu.flags.param_sel -1] = thresoldLow[info_menu.flags.param_sel -1]; \n } \n }\n } \n\n if(sel == DEC_MENU) \n {\n if(info_menu.flags.edit == 2)\n {\n if(--thresoldValue[info_menu.flags.param_sel -1] < thresoldLow[info_menu.flags.param_sel -1])\n {\n thresoldValue[info_menu.flags.param_sel -1] = thresoldHigh[info_menu.flags.param_sel -1]; \n }\n } \n }\n}\n\n// Funci\u00f3n para convertir decimal a BCD sin usar divisiones\nvoid decimal_to_bcd(uint16_t decimal) \n{\n // Limitar el rango a 0-999\n if (decimal > 999) decimal = 999;\n\n ///uint8_t hundreds = 0, tens = 0, units = 0;\n paramToView[2] = paramToView[1] = paramToView[0] = 16;\n\n // Calcular centenas (resta iterativa)\n while (decimal >= 100) {\n decimal -= 100;\n paramToView[2]++;\n }\n\n // Calcular decenas (resta iterativa)\n while (decimal >= 10) {\n decimal -= 10;\n paramToView[1]++;\n }\n\n // El restante son las unidades\n paramToView[0] += decimal;\n\n ///uint16_t bcd = (hundreds << 8) | (tens << 4) | units;\n ///return bcd;\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Mauricio Bautista\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-nano\", \"id\": \"nano\", \"top\": 120, \"left\": 28.3, \"attrs\": {} },\n {\n \"type\": \"wokwi-7segment\",\n \"id\": \"sevseg1\",\n \"top\": -109.38,\n \"left\": -104.76,\n \"attrs\": { \"digits\": \"3\", \"colon\": \"\", \"common\": \"cathode\" }\n },\n {\n \"type\": \"wokwi-pushbutton-6mm\",\n \"id\": \"btn1\",\n \"top\": 113,\n \"left\": 249.6,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-pushbutton-6mm\",\n \"id\": \"btn2\",\n \"top\": 141.8,\n \"left\": 249.6,\n \"attrs\": { \"color\": \"green\" }\n },\n { \"type\": \"wokwi-74hc595\", \"id\": \"sr1\", \"top\": -30, \"left\": 178.24, \"attrs\": {} },\n { \"type\": \"wokwi-gnd\", \"id\": \"gnd1\", \"top\": -134.4, \"left\": 306.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-pushbutton-6mm\",\n \"id\": \"btn3\",\n \"top\": 84.2,\n \"left\": 249.6,\n \"attrs\": { \"color\": \"green\" }\n }\n ],\n \"connections\": [\n [ \"nano:GND.1\", \"btn2:2.r\", \"black\", [ \"v28.8\", \"h153.6\", \"v-76.8\" ] ],\n [ \"nano:GND.1\", \"btn1:2.r\", \"black\", [ \"v28.8\", \"h153.6\", \"v-115.2\" ] ],\n [ \"nano:8\", \"btn1:1.l\", \"green\", [ \"v-38.4\", \"h153.6\", \"v28.8\" ] ],\n [ \"nano:7\", \"btn2:1.l\", \"green\", [ \"v-28.8\", \"h134.4\", \"v48\" ] ],\n [ \"sr1:Q0\", \"sevseg1:A\", \"green\", [ \"v-114\", \"h-220.8\" ] ],\n [ \"sr1:Q1\", \"sevseg1:B\", \"green\", [ \"v9.6\", \"h-19.2\", \"v-144\", \"h-153.6\", \"v28.8\" ] ],\n [ \"sevseg1:C\", \"sr1:Q2\", \"green\", [ \"v56.76\", \"h9.6\" ] ],\n [ \"sr1:Q3\", \"sevseg1:D\", \"green\", [ \"v28.8\", \"h-211.2\" ] ],\n [ \"sevseg1:E\", \"sr1:Q4\", \"green\", [ \"v75.96\", \"h240.01\" ] ],\n [ \"sevseg1:F\", \"sr1:Q5\", \"green\", [ \"v-48\", \"h172.8\", \"v201.6\", \"h57.6\" ] ],\n [ \"sevseg1:G\", \"sr1:Q6\", \"green\", [ \"v95.16\", \"h230.4\" ] ],\n [ \"sr1:Q7\", \"sevseg1:DP\", \"green\", [ \"v67.2\", \"h-249.6\" ] ],\n [ \"sr1:GND\", \"sr1:OE\", \"black\", [ \"v9.6\", \"h28.8\", \"v-67.2\", \"h-67.2\" ] ],\n [ \"gnd1:GND\", \"sr1:GND\", \"black\", [ \"v-19.2\", \"h-38.4\", \"v163.2\", \"h-28.8\" ] ],\n [ \"nano:GND.1\", \"gnd1:GND\", \"black\", [ \"v28.8\", \"h153.6\", \"v-220.8\", \"h57.6\", \"v-48\" ] ],\n [ \"nano:5V\", \"sr1:VCC\", \"red\", [ \"v38.4\", \"h182.4\", \"v-288\", \"h-134.4\" ] ],\n [ \"nano:5V\", \"sr1:MR\", \"red\", [ \"v38.4\", \"h182.4\", \"v-268.8\", \"h-96\" ] ],\n [ \"nano:10\", \"sr1:STCP\", \"yellow\", [ \"v-124.8\", \"h57.6\", \"v-76.8\", \"h48\" ] ],\n [ \"nano:11\", \"sr1:SHCP\", \"yellow\", [ \"v-134.4\", \"h57.6\", \"v-76.8\", \"h115.2\" ] ],\n [ \"sevseg1:DIG1\", \"nano:6\", \"blue\", [ \"v-38.4\", \"h-76.79\", \"v249.6\", \"h220.8\" ] ],\n [ \"nano:5\", \"sevseg1:DIG2\", \"blue\", [ \"v-28.8\", \"h-240\", \"v-220.8\", \"h115.2\" ] ],\n [ \"nano:4\", \"sevseg1:DIG3\", \"blue\", [ \"v-38.4\", \"h-259.2\", \"v-249.6\", \"h134.4\" ] ],\n [ \"nano:3\", \"sevseg1:DIG4\", \"blue\", [ \"v-48\", \"h-115.2\" ] ],\n [ \"nano:12\", \"sr1:DS\", \"yellow\", [ \"v-144\", \"h57.6\", \"v-28.8\", \"h96\" ] ],\n [ \"nano:GND.1\", \"btn3:2.r\", \"black\", [ \"v28.8\", \"h153.6\", \"v-105.6\" ] ],\n [ \"nano:9\", \"btn3:1.l\", \"green\", [ \"v-48\", \"h163.2\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for temperature control system using arduino", + "input": "#include \n#include \n#include \n#include \n#include \n#include \n\n// Pin Definitions\n#define BLUE 7 // Start indecator Blue LED\n#define RED 12 // Holding high temp indecator Red LED\n#define YELOW 8 // Holding LOW temp indecator Yelow LED\n#define DS18B20_PIN 2 // DS18B20 connected to digital pin 2\n#define RELAY_PIN 6 // Relay to control the heater\n#define STOP_BUTTON_PIN 9 // Stop button\n#define ENCODER_PIN_A 3 // Rotary encoder A\n#define ENCODER_PIN_B 4 // Rotary encoder B\n#define ENCODER_BUTTON 5 // Rotary encoder button\n\n// Initialize LCD (I2C address 0x27 for a 20x4 display)\nLiquidCrystal_I2C lcd(0x27, 20, 4);\n\n// Initialize OneWire and DS18B20\nOneWire oneWire(DS18B20_PIN);\nDallasTemperature sensors(&oneWire);\n\n// Initialize RTC\nRTC_DS1307 rtc;\n\n// Initialize rotary encoder\nEncoder encoder(ENCODER_PIN_A, ENCODER_PIN_B);\n\n// Variables\nfloat currentTemperature = 0.0;\nfloat highTemp = 0.0; // Default high temperature\nfloat lowTemp = 0.0; // Default low temperature\nint holdTime = 0; // Default hold time in minutes\nbool heatingStarted = false;\nbool holdTimeTracking = false;\nbool lowTempTracking = false;\nbool heating = false;\nbool tempering = false;\nbool keep_low_temp = false;\n\nDateTime holdStartTime;\nDateTime lowTempStartTime;\n\n// Button State Tracking for Debouncing\nbool lastEncoderButtonState = HIGH;\nbool lastStopButtonState = HIGH;\n\n// Encoder menu states\nint state = 0; // 0 = Set High Temp, 1 = Set Hold Time, 2 = Set Low Temp, 3 = Ready to Start\n\nvoid setup() {\n // Initialize serial monitor\n Serial.begin(9600);\n\n // Initialize LCD\n lcd.init();\n lcd.backlight();\n\n // Initialize DS18B20\n sensors.begin();\n\n // Initialize RTC\n if (!rtc.begin()) {\n lcd.setCursor(0, 0);\n lcd.print(\"RTC Not Found!\");\n while (1);\n }\n if (!rtc.isrunning()) {\n rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set to compile time\n }\n\n // Initialize pins\n pinMode(RED, OUTPUT);\n pinMode(YELOW, OUTPUT);\n pinMode(RELAY_PIN, OUTPUT);\n pinMode(STOP_BUTTON_PIN, INPUT_PULLUP);\n pinMode(ENCODER_BUTTON, INPUT_PULLUP);\n\n // Ensure heater is off at startup\n digitalWrite(RELAY_PIN, LOW);\n\n // Welcome Message\n lcd.setCursor(6, 1);\n lcd.print(\"STARTING\");\n lcd.setCursor(7, 2);\n lcd.print(\"SYSTEM\");\n delay(2000);\n lcd.clear();\n}\n\nvoid loop() {\n // Request temperature from DS18B20\n sensors.requestTemperatures();\n currentTemperature = sensors.getTempCByIndex(0);\n\n // Read rotary encoder position\n long encoderPosition = encoder.read() / 4;\n\n // Read buttons\n bool encoderButtonPressed = digitalRead(ENCODER_BUTTON) == LOW;\n bool stopButtonPressed = digitalRead(STOP_BUTTON_PIN) == LOW;\n\n // Handle encoder button press\n if (encoderButtonPressed && lastEncoderButtonState == HIGH) {\n delay(50); // Debounce delay\n if (digitalRead(ENCODER_BUTTON) == LOW) {\n state = (state + 1) % 4; // Cycle through menu states\n encoder.write(0); // Reset encoder position\n lcd.clear();\n }\n }\n lastEncoderButtonState = encoderButtonPressed;\n\n // Handle stop button press\n if (stopButtonPressed && lastStopButtonState == HIGH) {\n delay(50); // Debounce delay\n if (digitalRead(STOP_BUTTON_PIN) == LOW) {\n heatingStarted = false;\n holdTimeTracking = false;\n lowTempTracking = false;\n digitalWrite(RELAY_PIN, LOW); // Turn off heater\n lcd.clear();\n lcd.setCursor(2, 0);\n lcd.print(\"Process Stopped\");\n lcd.setCursor(6, 1);\n lcd.print(\"Restart\");\n lcd.setCursor(6, 2);\n lcd.print(\".......\");\n delay(200);\n lcd.clear();\n return; // Exit loop to ensure heating is off\n }\n }\n lastStopButtonState = stopButtonPressed;\n\n // Update LCD\n updateLCD(encoderPosition);\n\n // Start heating process if in \"Ready to Start\" state\n if (state == 3 && !heatingStarted) {\n heatingStarted = true;\n heating = true;\n lcd.clear();\n lcd.setCursor(7, 1);\n lcd.print(\"Start\");\n lcd.setCursor(6, 2);\n lcd.print(\"Heating.... \");\n delay(3000);\n lcd.clear();\n digitalWrite(RELAY_PIN, HIGH); // Turn on heater\n lcd.setCursor(0, 2);\n lcd.print(\"Go to High \");\n }\n\n // Control heating and time tracking\n if (heatingStarted) {\n controlHeating();\n }\n delay(50); // Short delay for stability\n}\n\nvoid updateLCD(long encoderPosition) {\n lcd.setCursor(4, 0);\n lcd.print(\"Temp: \");\n lcd.print(currentTemperature);\n lcd.print(\" C \");\n\n if (state == 0) { // Set High Temperature\n highTemp = constrain(0 + encoderPosition * 5, 0, 400); // Adjust high temperature\n lcd.setCursor(0, 2);\n lcd.print(\"Set High Temp:\");\n lcd.setCursor(0, 3);\n //lcd.print(\"High Temp: \");\n lcd.print(highTemp);\n lcd.print(\" C \");\n } else if (state == 1) { // Set Hold Time\n holdTime = constrain(1 + encoderPosition , 0, 240); // Adjust hold time\n lcd.setCursor(0, 2);\n lcd.print(\"Set Hold Time: \");\n lcd.setCursor(0, 3);\n //lcd.print(\"Hold Time: \");\n if(holdTime>60) {\n lcd.print(holdTime/60);\n lcd.print(\"h \");\n lcd.print(holdTime%60);\n lcd.print(\"min\");\n } else {\n lcd.print(holdTime);\n lcd.print(\" min \");\n }\n } else if (state == 2) { // Set Low Temperature\n lowTemp = constrain(0 + encoderPosition * 5, 0, highTemp - 1); // Adjust low temperature\n lcd.setCursor(0, 2);\n lcd.print(\"Set Low Temp:\");\n lcd.setCursor(0, 3);\n //lcd.print(\"Low Temp: \");\n lcd.print(lowTemp);\n lcd.print(\" C \");\n } else if (state == 3) { // Ready to Start\n lcd.setCursor(0, 1);\n lcd.print(\"Starting \");\n }\n}\n\nvoid controlHeating() {\n\n if(heating && currentTemperature < highTemp) {\n //continue heating to high temperature\n } else if(heating && currentTemperature >= (highTemp+1)) {\n heating = false;\n tempering = true;\n digitalWrite(RELAY_PIN, LOW); // Turn off heater\n lcd.setCursor(0, 2);\n lcd.print(\"Reached High \");\n holdStartTime = rtc.now(); // Start hold time tracking\n holdTimeTracking = true;\n digitalWrite(RED, HIGH);\n\n } else if(tempering) {\n DateTime now = rtc.now();\n TimeSpan elapsed = now - holdStartTime;\n\n if(elapsed.minutes() >= holdTime) {\n digitalWrite(RELAY_PIN, LOW); // Turn off heater\n holdTimeTracking = false;\n digitalWrite(RED, LOW);\n tempering = false;\n keep_low_temp = true;\n lcd.setCursor(0, 3);\n lcd.print(\"Time Over H \");\n } else {\n lcd.setCursor(0, 3);\n lcd.print(\"Hold H temp: \");\n lcd.print(elapsed.minutes());\n lcd.print(\"m \");\n lcd.print(elapsed.seconds());\n lcd.print(\"s \");\n if(currentTemperature >= (highTemp+1)) {\n digitalWrite(RELAY_PIN, LOW); // Turn off heater\n } else if(currentTemperature < (highTemp-1)) {\n digitalWrite(RELAY_PIN, HIGH); // Turn on heater\n }\n }\n } else if(keep_low_temp) {\n if(currentTemperature>(lowTemp-3) && currentTemperature<(lowTemp+3) && !lowTempTracking) {\n lowTempTracking = true;\n digitalWrite(YELOW, HIGH);\n holdStartTime = rtc.now(); // Start hold time tracking (Low)\n } else if(lowTempTracking) {\n DateTime now = rtc.now();\n TimeSpan elapsed = now - holdStartTime;\n lcd.setCursor(0, 3);\n lcd.print(\"Hold L temp: \");\n lcd.print(elapsed.minutes());\n lcd.print(\"m \");\n lcd.print(elapsed.seconds());\n lcd.print(\"s \");\n if(currentTemperature >= (lowTemp+1)) {\n digitalWrite(RELAY_PIN, LOW); // Turn off heater\n } else if(currentTemperature < (lowTemp-1)) {\n digitalWrite(RELAY_PIN, HIGH); // Turn on heater\n }\n }\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"board-ds18b20\", \"id\": \"temp1\", \"top\": 75.67, \"left\": -159.12, \"attrs\": {} },\n {\n \"type\": \"wokwi-lcd2004\",\n \"id\": \"lcd1\",\n \"top\": 6.4,\n \"left\": 322.4,\n \"attrs\": { \"pins\": \"i2c\" }\n },\n { \"type\": \"wokwi-ky-040\", \"id\": \"encoder1\", \"top\": -151.9, \"left\": -144.8, \"attrs\": {} },\n { \"type\": \"wokwi-relay-module\", \"id\": \"relay1\", \"top\": -163, \"left\": 460.8, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": 73.2,\n \"left\": 723.8,\n \"attrs\": { \"color\": \"limegreen\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": -15.8,\n \"left\": 728.75,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"450000\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn2\",\n \"top\": 227,\n \"left\": 576,\n \"attrs\": { \"color\": \"red\", \"key\": \"2\" }\n },\n { \"type\": \"wokwi-ds1307\", \"id\": \"rtc1\", \"top\": 359.4, \"left\": 268.9, \"attrs\": {} },\n { \"type\": \"wokwi-microsd-card\", \"id\": \"sd1\", \"top\": 355.43, \"left\": -86.33, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 167.15,\n \"left\": -124.8,\n \"attrs\": { \"value\": \"5000\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": 140.4,\n \"left\": 752.6,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": 140.4,\n \"left\": 791,\n \"attrs\": { \"color\": \"orange\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led4\",\n \"top\": -70.8,\n \"left\": 320.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 216,\n \"left\": 748.25,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"450000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r4\",\n \"top\": 216,\n \"left\": 786.65,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"450000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r5\",\n \"top\": -53.35,\n \"left\": 382.6,\n \"rotate\": 180,\n \"attrs\": { \"value\": \"450000\" }\n }\n ],\n \"connections\": [\n [ \"temp1:VCC\", \"uno:5V\", \"red\", [ \"v124.8\", \"h294.4\" ] ],\n [ \"uno:GND.2\", \"temp1:GND\", \"black\", [ \"v38.9\", \"h-236.7\" ] ],\n [ \"lcd1:GND\", \"uno:GND.1\", \"black\", [ \"h-48\", \"v-67.2\", \"h-163.2\" ] ],\n [ \"lcd1:VCC\", \"uno:5V\", \"red\", [ \"h-48\", \"v172.9\", \"h-124.8\" ] ],\n [ \"lcd1:SDA\", \"uno:A4\", \"green\", [ \"h-38.4\", \"v182.6\", \"h-38.4\" ] ],\n [ \"lcd1:SCL\", \"uno:A5\", \"green\", [ \"h-19.2\", \"v182.7\", \"h-38.4\" ] ],\n [ \"encoder1:GND\", \"uno:GND.1\", \"black\", [ \"h0\" ] ],\n [ \"encoder1:VCC\", \"uno:5V\", \"red\", [ \"h48\", \"v58\", \"h-28.8\", \"v278.4\", \"h172.8\" ] ],\n [ \"encoder1:SW\", \"uno:5\", \"green\", [ \"h0\" ] ],\n [ \"relay1:VCC\", \"uno:5V\", \"red\", [ \"h-163.2\", \"v412.8\", \"h-137.6\" ] ],\n [ \"relay1:GND\", \"uno:GND.1\", \"black\", [ \"h-201.6\", \"v86\", \"h-124.8\" ] ],\n [ \"relay1:COM\", \"led1:C\", \"green\", [ \"h49.2\", \"v46.6\", \"h96\", \"v201.6\" ] ],\n [ \"r2:1\", \"led1:A\", \"green\", [ \"v0\" ] ],\n [ \"relay1:NO\", \"uno:GND.1\", \"green\", [ \"h30\", \"v55.8\", \"h-489.6\", \"v9.6\" ] ],\n [ \"relay1:IN\", \"uno:6\", \"green\", [ \"h0\" ] ],\n [ \"rtc1:5V\", \"uno:5V\", \"red\", [ \"h0\" ] ],\n [ \"rtc1:GND\", \"uno:GND.2\", \"black\", [ \"h0\" ] ],\n [ \"rtc1:SDA\", \"uno:A4\", \"green\", [ \"h0\" ] ],\n [ \"rtc1:SCL\", \"uno:A5\", \"green\", [ \"h0\" ] ],\n [ \"btn2:1.r\", \"uno:9\", \"green\", [ \"v0\", \"h57.8\", \"v-259.2\", \"h-537.6\" ] ],\n [ \"temp1:DQ\", \"uno:2\", \"green\", [ \"v19.2\", \"h86.4\", \"v-182.4\", \"h307.2\" ] ],\n [ \"r1:1\", \"temp1:DQ\", \"green\", [ \"v-19.2\", \"h-19.2\" ] ],\n [ \"r1:2\", \"temp1:VCC\", \"green\", [ \"v0\" ] ],\n [ \"uno:3\", \"encoder1:DT\", \"green\", [ \"v0\" ] ],\n [ \"uno:4\", \"encoder1:CLK\", \"green\", [ \"v0\" ] ],\n [ \"uno:GND.3\", \"btn2:2.l\", \"black\", [ \"v0\" ] ],\n [ \"led2:A\", \"r3:1\", \"green\", [ \"v0\" ] ],\n [ \"r3:2\", \"uno:12\", \"green\", [ \"h0\", \"v27.6\", \"h-460.8\", \"v-364.8\", \"h-153.6\" ] ],\n [ \"led2:C\", \"uno:GND.3\", \"green\", [ \"v86.4\", \"h-95.6\", \"v38.4\", \"h-9.6\" ] ],\n [ \"r4:1\", \"led3:A\", \"green\", [ \"h0\" ] ],\n [ \"led3:C\", \"led2:C\", \"green\", [ \"v9.6\", \"h-18.8\", \"v-48\", \"h-28.8\", \"v38.4\" ] ],\n [ \"r4:2\", \"uno:8\", \"green\", [ \"h0\", \"v75.6\", \"h-844.8\", \"v-403.2\", \"h211.2\" ] ],\n [ \"led4:C\", \"uno:7\", \"green\", [ \"v0\", \"h-9.2\", \"v-48\", \"h-134.4\" ] ],\n [ \"r5:2\", \"led4:A\", \"green\", [ \"v0\", \"h-8.4\", \"v19.2\" ] ],\n [ \"r5:1\", \"lcd1:VCC\", \"green\", [ \"v0\", \"h9.6\", \"v19.2\", \"h-67.2\", \"v28.8\", \"h-96\", \"v48\" ] ],\n [ \"relay1:VCC\", \"r2:2\", \"red\", [ \"h-9.6\", \"v-28.8\", \"h182.4\", \"v67.2\", \"h124.8\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Gost28147", + "input": "#include \n\n// Default S-Box (GOST 28147-89 standard)\nuint8_t S_BOX[8][16] = {\n {4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3},\n {14, 11, 4, 12, 6, 13, 15, 10, 2, 3, 8, 1, 0, 7, 5, 9},\n {5, 8, 1, 13, 10, 3, 4, 2, 14, 15, 12, 7, 6, 0, 9, 11},\n {7, 13, 10, 1, 0, 8, 9, 15, 14, 4, 6, 12, 11, 2, 5, 3},\n {6, 12, 7, 1, 5, 15, 13, 8, 4, 10, 9, 14, 0, 3, 11, 2},\n {4, 11, 10, 0, 7, 2, 1, 13, 3, 6, 8, 5, 9, 12, 15, 14},\n {13, 11, 4, 1, 3, 15, 5, 9, 0, 10, 14, 7, 6, 8, 2, 12},\n {1, 15, 13, 0, 5, 7, 10, 4, 9, 2, 3, 14, 6, 11, 8, 12}\n};\n\n// R function with S-Box substitution\nuint32_t R(uint32_t x) {\n uint32_t result = 0;\n for (int i = 0; i < 8; i++) {\n uint8_t part = (x >> (4 * (7 - i))) & 0xF;\n result |= ((uint32_t)S_BOX[i][part]) << (4 * (7 - i));\n }\n result = (result << 11) | (result >> (32 - 11));\n return result;\n}\n\n// Encrypt a single block (64 bits)\nvoid gost_encrypt(uint32_t *block, uint32_t *key) {\n uint32_t n1 = block[0];\n uint32_t n2 = block[1];\n\n for (int i = 0; i < 24; i++) {\n uint32_t temp = n1;\n n1 = n2 ^ R(n1 + key[i % 8]);\n n2 = temp;\n }\n for (int i = 7; i >= 0; i--) {\n uint32_t temp = n1;\n n1 = n2 ^ R(n1 + key[i]);\n n2 = temp;\n }\n\n block[0] = n1;\n block[1] = n2;\n}\n\n// Decrypt a single block (64 bits)\nvoid gost_decrypt(uint32_t *block, uint32_t *key) {\n uint32_t n1 = block[1];\n uint32_t n2 = block[0];\n\n for (int i = 0; i < 8; i++) {\n uint32_t temp = n1;\n n1 = n2 ^ R(n1 + key[i]);\n n2 = temp;\n }\n for (int i = 23; i >= 0; i--) {\n uint32_t temp = n1;\n n1 = n2 ^ R(n1 + key[i % 8]);\n n2 = temp;\n }\n\n block[0] = n2;\n block[1] = n1;\n}\n\n// Add PKCS#7 padding\nvoid add_padding(uint8_t *data, size_t &length) {\n size_t padding = 8 - (length % 8);\n for (size_t i = 0; i < padding; i++) {\n data[length + i] = padding;\n }\n length += padding;\n}\n\n// Remove PKCS#7 padding\nvoid remove_padding(uint8_t *data, size_t &length) {\n uint8_t padding = data[length - 1];\n if (padding > 0 && padding <= 8) {\n length -= padding;\n }\n}\n\nvoid gost_encrypt_with_padding(uint8_t *data, size_t &length, uint32_t *key) {\n // To\u2018ldirish qo\u2018shish\n add_padding(data, length);\n\n // Har bir blokni shifrlash\n for (size_t i = 0; i < length; i += 8) {\n gost_encrypt((uint32_t *)&data[i], key);\n }\n}\n\nvoid gost_decrypt_with_padding(uint8_t *data, size_t &length, uint32_t *key) {\n // Har bir blokni deshifrlash\n for (size_t i = 0; i < length; i += 8) {\n gost_decrypt((uint32_t *)&data[i], key);\n }\n\n // To\u2018ldirishni olib tashlash\n remove_padding(data, length);\n}\n\nvoid setup() {\n Serial.begin(9600);\n}\n\nvoid loop() {\n if (Serial.available() > 0) {\n String command = Serial.readStringUntil('\\n');\n String inputData = command.substring(8);\n size_t length = inputData.length();\n uint8_t data[1024];\n inputData.getBytes(data, sizeof(data));\n uint32_t key[8] = {0x12345678, 0x23456789, 0x34567890, 0x45678901,\n 0x56789012, 0x67890123, 0x78901234, 0x89012345};\n if (command.startsWith(\"ENCRYPT:\")) {\n gost_encrypt_with_padding(data, length, key);\n for (size_t i = 0; i < length; i++) {\n if(data[i] < 16){\n Serial.print(\"0\");\n Serial.print(data[i], HEX);\n }else{\n Serial.print(data[i], HEX);\n }\n }\n } else if (command.startsWith(\"DECRYPT:\")) {\n\n size_t length1 = length / 2; // Har ikkita HEX belgidan bitta byte hosil bo'ladi\n uint8_t data[length1]; // uint8_t massiv\n\n // HEX dan uint8_t ga o'zgartirish\n for (size_t i = 0; i < length1; i++) {\n String byteString = inputData.substring(i * 2, i * 2 + 2); // 2 ta HEX belgi olish\n data[i] = (uint8_t) strtoul(byteString.c_str(), NULL, 16); // HEX ni uint8_t ga aylantirish\n }\n gost_decrypt_with_padding(data, length1, key);\n for (size_t i = 0; i < length1; i++) {\n Serial.print((char)data[i]);\n }\n } else {\n Serial.println(\"Unknown command!\");\n }\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Programmer GPT\",\n \"editor\": \"wokwi\",\n \"parts\": [ { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0, \"left\": 0, \"attrs\": {} } ],\n \"connections\": [],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Three LED blink in series", + "input": "#define RED_LED 7\n#define GREEN_LED 6\n#define BLUE_LED 5\n\nvoid setup() {\n pinMode(RED_LED, OUTPUT);\n pinMode(GREEN_LED, OUTPUT);\n pinMode(BLUE_LED, OUTPUT);\n}\n\nvoid loop() {\n digitalWrite(RED_LED, HIGH);\n digitalWrite(GREEN_LED, LOW);\n digitalWrite(BLUE_LED, LOW);\n delay(1000); \n\n digitalWrite(RED_LED, LOW);\n digitalWrite(GREEN_LED, HIGH);\n digitalWrite(BLUE_LED, LOW);\n delay(1000); \n\n digitalWrite(RED_LED, LOW);\n digitalWrite(GREEN_LED, LOW);\n digitalWrite(BLUE_LED, HIGH);\n delay(1000); \n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-half\", \"id\": \"bb1\", \"top\": -12.6, \"left\": 300.4, \"attrs\": {} },\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0.6, \"left\": 37.8, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -3.6, \"left\": 339.8, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -3.6,\n \"left\": 435.8,\n \"attrs\": { \"color\": \"limegreen\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": -3.6,\n \"left\": 531.8,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 81.6,\n \"left\": 335.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"0\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 81.6,\n \"left\": 431.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 81.6,\n \"left\": 527.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"1000\" }\n }\n ],\n \"connections\": [\n [ \"led1:C\", \"bb1:4t.b\", \"green\", [ \"v9.6\", \"h0.4\" ] ],\n [ \"led2:C\", \"bb1:14t.b\", \"green\", [ \"v9.6\", \"h0.4\" ] ],\n [ \"led2:A\", \"bb1:15t.b\", \"green\", [ \"v9.6\" ] ],\n [ \"led3:C\", \"bb1:24t.b\", \"green\", [ \"v9.6\", \"h0.4\" ] ],\n [ \"led3:A\", \"bb1:25t.b\", \"green\", [ \"v9.6\" ] ],\n [ \"led1:A\", \"bb1:5t.a\", \"\", [ \"$bb\" ] ],\n [ \"led1:C\", \"bb1:4t.a\", \"\", [ \"$bb\" ] ],\n [ \"led2:A\", \"bb1:15t.a\", \"\", [ \"$bb\" ] ],\n [ \"led2:C\", \"bb1:14t.a\", \"\", [ \"$bb\" ] ],\n [ \"led3:A\", \"bb1:25t.a\", \"\", [ \"$bb\" ] ],\n [ \"led3:C\", \"bb1:24t.a\", \"\", [ \"$bb\" ] ],\n [ \"bb1:5t.b\", \"led1:A\", \"green\", [ \"v0\" ] ],\n [ \"r1:1\", \"bb1:5t.c\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"bb1:5b.g\", \"\", [ \"$bb\" ] ],\n [ \"r2:1\", \"bb1:15t.c\", \"\", [ \"$bb\" ] ],\n [ \"r2:2\", \"bb1:15b.g\", \"\", [ \"$bb\" ] ],\n [ \"r3:1\", \"bb1:25t.c\", \"\", [ \"$bb\" ] ],\n [ \"r3:2\", \"bb1:25b.g\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"uno:7\", \"red\", [ \"h-38.4\", \"v-164.4\", \"h-105.6\", \"v19.2\" ] ],\n [ \"r2:2\", \"uno:6\", \"green\", [ \"h19.2\", \"v-174\", \"h-240\", \"v38.4\" ] ],\n [ \"r3:2\", \"uno:5\", \"blue\", [ \"h19.2\", \"v-202.8\", \"h0\", \"v0\", \"h-316.8\", \"v67.2\" ] ],\n [ \"bb1:4t.d\", \"bb1:bn.3\", \"purple\", [ \"v115.2\" ] ],\n [ \"bb1:14t.d\", \"bb1:bn.11\", \"purple\", [ \"v115.2\" ] ],\n [ \"bb1:24t.d\", \"bb1:bn.20\", \"purple\", [ \"v115.2\" ] ],\n [ \"bb1:bp.1\", \"uno:5V\", \"red\", [ \"v47.1\", \"h-132.8\" ] ],\n [ \"bb1:bn.2\", \"uno:GND.3\", \"green\", [ \"v27.5\", \"h-123.2\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for piano using arduino", + "input": "#include \"pitches.h\"\n#define SPEAKER_PIN 8\nconst uint8_t buttonPins[]={12,11,10,9,8,7,6,5,4};\nconst int buttonTones[]={\n NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,\n NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5\n};\nconst int numTones= sizeof(buttonPins) / sizeof (buttonPins[0]);\n\n\nvoid setup() {\n int pitch=0;// put your setup code here, to run once:\nfor (uint8_t i=0; i< numTones;i++){\n pinMode(buttonPins[i], INPUT_PULLUP);\n}\npinMode(SPEAKER_PIN, OUTPUT);\n}\n\nvoid loop() {\n int pitch=0;\n for (uint8_t i=0; i < numTones; i++){\n if (digitalRead(buttonPins[i])== LOW){\n pitch = buttonTones[i];\n }\n \n }\nif (pitch) {\n tone(SPEAKER_PIN, pitch);\n}\nelse {\n tone(SPEAKER_PIN,0);\n}\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -55.2,\n \"left\": 366.6,\n \"attrs\": { \"volume\": \"0.1\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn2\",\n \"top\": -96.1,\n \"left\": 233.9,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"yellow\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn3\",\n \"top\": -105.7,\n \"left\": 185.9,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"yellow\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn4\",\n \"top\": -105.7,\n \"left\": 137.9,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"green\", \"bounce\": \"1\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn5\",\n \"top\": -115.3,\n \"left\": 89.9,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn8\",\n \"top\": -115.3,\n \"left\": -63.7,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": -96.1,\n \"left\": 291.5,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn6\",\n \"top\": -124.9,\n \"left\": -6.1,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn7\",\n \"top\": -144.1,\n \"left\": 41.9,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"blue\" }\n }\n ],\n \"connections\": [\n [ \"btn1:1.r\", \"uno:4\", \"red\", [ \"v0\" ] ],\n [ \"btn2:1.r\", \"uno:5\", \"orange\", [ \"v0\" ] ],\n [ \"btn3:1.r\", \"uno:6\", \"gold\", [ \"v0\" ] ],\n [ \"btn5:1.r\", \"uno:9\", \"cyan\", [ \"v0\" ] ],\n [ \"btn8:1.r\", \"uno:12\", \"red\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"btn5:2.r\", \"black\", [ \"v-76.2\", \"h-0.3\" ] ],\n [ \"uno:GND.1\", \"btn7:2.r\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"btn6:2.r\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"btn8:2.r\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"btn4:2.r\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"btn3:2.r\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"btn2:2.r\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"btn1:2.r\", \"black\", [ \"v0\" ] ],\n [ \"btn6:1.r\", \"uno:11\", \"purple\", [ \"v0\" ] ],\n [ \"btn7:1.r\", \"uno:10\", \"blue\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"bz1:1\", \"black\", [ \"v0\" ] ],\n [ \"bz1:2\", \"uno:8\", \"green\", [ \"v0\" ] ],\n [ \"uno:7\", \"btn4:1.r\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for sequential LED tower", + "input": "void setup() {\n pinMode(10, OUTPUT);\n pinMode(9, OUTPUT);\n pinMode(8, OUTPUT);\n pinMode(7, OUTPUT);\n pinMode(6, OUTPUT);\n pinMode(5, OUTPUT);\n pinMode(4, OUTPUT);\n pinMode(3, OUTPUT);\n pinMode(2, INPUT_PULLUP);\n // put your setup code here, to run once:\n\n}\n\nvoid loop() {\n int pb1=digitalRead(2);\n\n if(pb1==LOW)\n {\n digitalWrite(4, HIGH);\n digitalWrite(10, HIGH);\n delay(250);\n digitalWrite(4, LOW);\n digitalWrite(10, LOW);\n digitalWrite(3, HIGH);\n digitalWrite(9, HIGH);\n delay(250);\n digitalWrite(3, LOW);\n digitalWrite(9, LOW);\n digitalWrite(6, HIGH);\n digitalWrite(8, HIGH);\n delay(250);\n digitalWrite(6, LOW);\n digitalWrite(8, LOW);\n digitalWrite(5, HIGH);\n digitalWrite(7, HIGH);\n delay(250);\n digitalWrite(5, LOW);\n digitalWrite(7, LOW);\n digitalWrite(10, HIGH);\n digitalWrite(9, HIGH);\n delay(250);\n digitalWrite(10, LOW);\n digitalWrite(9, LOW);\n digitalWrite(8, HIGH);\n digitalWrite(7, HIGH);\n delay(250);\n digitalWrite(8, LOW);\n digitalWrite(7, LOW);\n digitalWrite(6, HIGH);\n digitalWrite(5, HIGH);\n delay(250);\n digitalWrite(6, LOW);\n digitalWrite(5, LOW);\n digitalWrite(4, HIGH);\n digitalWrite(3, HIGH);\n delay(250);\n digitalWrite(4, LOW);\n digitalWrite(3, LOW);\n digitalWrite(3, HIGH);\n digitalWrite(4, HIGH);\n delay(250);\n digitalWrite(3, LOW);\n digitalWrite(4, LOW);\n digitalWrite(5, HIGH);\n digitalWrite(6, HIGH);\n delay(250);\n digitalWrite(5, LOW);\n digitalWrite(6, LOW);\n digitalWrite(7, HIGH);\n digitalWrite(8, HIGH);\n delay(250);\n digitalWrite(7, LOW);\n digitalWrite(8, LOW);\n digitalWrite(9, HIGH);\n digitalWrite(10, HIGH);\n delay(250);\n digitalWrite(9, LOW);\n digitalWrite(10, LOW);\n }\n // put your main code here, to run repeatedly:\n\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Mas Wan\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0.6, \"left\": -0.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": -61,\n \"left\": 19.2,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": -118.8,\n \"left\": 128.6,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -118.8,\n \"left\": 176.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": -214.8,\n \"left\": 128.6,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led4\",\n \"top\": -166.8,\n \"left\": 128.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led5\",\n \"top\": -214.8,\n \"left\": 176.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led6\",\n \"top\": -166.8,\n \"left\": 176.6,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led7\",\n \"top\": -262.8,\n \"left\": 128.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led8\",\n \"top\": -262.8,\n \"left\": 176.6,\n \"attrs\": { \"color\": \"red\" }\n }\n ],\n \"connections\": [\n [ \"uno:GND.1\", \"btn1:2.r\", \"limegreen\", [ \"v0\" ] ],\n [ \"uno:2\", \"btn1:1.r\", \"green\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"led1:C\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"led2:C\", \"limegreen\", [ \"v0\" ] ],\n [ \"uno:3\", \"led1:A\", \"red\", [ \"v0\" ] ],\n [ \"uno:4\", \"led2:A\", \"blue\", [ \"v0\" ] ],\n [ \"uno:5\", \"led6:A\", \"red\", [ \"v0\" ] ],\n [ \"uno:6\", \"led4:A\", \"blue\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"led4:C\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"led6:C\", \"limegreen\", [ \"v0\" ] ],\n [ \"uno:7\", \"led3:A\", \"red\", [ \"v0\" ] ],\n [ \"uno:8\", \"led5:A\", \"blue\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"led3:C\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"led5:C\", \"limegreen\", [ \"v0\" ] ],\n [ \"uno:9\", \"led8:A\", \"red\", [ \"v0\" ] ],\n [ \"uno:10\", \"led7:A\", \"blue\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"led7:C\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"led8:C\", \"limegreen\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for modern turn lights motorcycles using arduino", + "input": "//Modern turn lights v.3.1.0 for scooters and motorcycles with arduino and ws2812b - by Fedaceag Ionut ( Youtube - Think small, build big! )\n#include //FastLed library version 3.2.1 - https://github.com/FastLED/FastLED/wiki/Overview or http://fastled.io/ with NEOPIXEL or WS2812B\n#define NUM_STRIPS 4 // number of small led strips\n\n#define NUM_LEDS_PART_A 20 // number of leds for the big strip - should be the at least the number of leds from the small strips multiply by tree (in this case the minimum should be 10 x 3 = 30 leds)\n#define NUM_LEDS_PART_B 4 // number of leds for the small strips\n\nCRGB ledsA[NUM_LEDS_PART_A];\nCRGB ledsB[NUM_STRIPS][NUM_LEDS_PART_B];\n\n//input pins\nconst int buttonPinL = 2; // turn left\nconst int buttonPinR = 3; // turn right\nconst int buttonPinEng = 4; // engine on to start day lights\nconst int buttonPinKnightRider = 5; // knight rider lights\nconst int buttonPinBrake = 6; // brake lights\nconst int buttonPinTailLights = 7; // tail lights\n\nint halfOfLeds = (NUM_LEDS_PART_A/2);\nint buttonStateL = 0;\nint buttonStateR = 0;\nint engineOn = 0;\nint maxBrtN = 0;\nint KnightRiderState = 0;\nint KnightRiderToOff = 0;\nint Brake = 0;\nint TailLights = 0;\nint leftLeds = 0;\nint rightLeds = 0;\nint tailLeft = halfOfLeds-1;\nint tailLeftSmall = 0;\nint tailRight = halfOfLeds;\nint tailRightSmall = 0;\nint brakeToOffL = 0;\nint brakeToOffR = 0;\n\nint stateLT = 0;\nint stateRT = 0;\nuint8_t gBrtL = 0;\nuint8_t gBrtR = 0;\nint TailOn = 0;\n\nunsigned long turnColor = 0xff6a00; //turn signal color\nint showSignalBigStrip = 1; // show the signal on the big led strip 0 = no | 1 = yes\nint showTailBrakeSmalStrip = 1; // show tail and brake lights on small strips 0 = no | 1 = yes\nint maxBrt = 254; // maxim brightness day lights - from 0 to 254\nint maxBrtNight = 100; // maxim brightness day lights with tail lights on - from 0 to 254\nint maxBrtBrake = 254; // maxim brightness Brake lights - from 0 to 254\nint maxBrtTailLights = 70; // maxim brightness tail lights - from 0 to 254\nuint8_t gHue = 0; // knight rider color\nint knightRiderRainbow = 0; // knight rider rainbow effect 0 = no | 1 = yes\nint knightRiderOvrDayL = 1; // knight rider override day lights 0 = no | 1 = yes\nint knightRiderSpeed = 45; // speed for knight rider lights\nint knightRiderTail = 12; // tail effect for knight rider lights\n\nint delayTurnLedAnim = 8; //delay of each led in turn light animation\nint delayTurnLedOff = 250; //delay from animation to black (is used twice)\nint delayLedToDayLight = 500; //delay from animation to day light on\nint tailDelay = 6; //delay for animation tail lights on or off\nint nrAnimAfterOff = 3; //number of animations for a single impulse\n\nunsigned long currentMillis = 0; \nunsigned long previousMillis = 0;\n\nvoid setup() { \n Serial.begin(115200);\n pinMode(buttonPinL, INPUT);\n pinMode(buttonPinR, INPUT);\n pinMode(buttonPinEng, INPUT);\n pinMode(buttonPinKnightRider, INPUT);\n pinMode(buttonPinBrake, INPUT);\n pinMode(buttonPinTailLights, INPUT);\n \n FastLED.addLeds(ledsA, NUM_LEDS_PART_A); //big led strip rear turn signals, brake light, tail lights\n FastLED.addLeds(ledsB[0], NUM_LEDS_PART_B); //led strip rear left turn signals\n FastLED.addLeds(ledsB[1], NUM_LEDS_PART_B); //led strip rear right turn signals\n FastLED.addLeds(ledsB[2], NUM_LEDS_PART_B); //led strip front left turn signals\n FastLED.addLeds(ledsB[3], NUM_LEDS_PART_B); //led strip front right turn signals\n \n attachInterrupt(digitalPinToInterrupt(buttonPinL),btnPressL,RISING); // we use interrupt for instant reaction of turn lights\n attachInterrupt(digitalPinToInterrupt(buttonPinR),btnPressR,RISING); // we use interrupt for instant reaction of turn lights\n\n fill_solid(ledsA, NUM_LEDS_PART_A, CRGB::Black); // some led strips are all on at power on, so let's power them off at boot\n fill_solid(ledsB[0], NUM_LEDS_PART_B, CRGB::Black); // some led strips are all on at power on, so let's power them off at boot\n fill_solid(ledsB[1], NUM_LEDS_PART_B, CRGB::Black); // some led strips are all on at power on, so let's power them off at boot\n fill_solid(ledsB[2], NUM_LEDS_PART_B, CRGB::Black); // some led strips are all on at power on, so let's power them off at boot\n fill_solid(ledsB[3], NUM_LEDS_PART_B, CRGB::Black); // some led strips are all on at power on, so let's power them off at boot\n \n FastLED.show();\n}\n\nvoid loop() {\n // read the input state\n buttonStateL = digitalRead(buttonPinL); \n buttonStateR = digitalRead(buttonPinR);\n engineOn = digitalRead(buttonPinEng);\n KnightRiderState = digitalRead(buttonPinKnightRider);\n Serial.print(buttonStateL);\n Serial.print(\", \");\n Serial.print(buttonStateR);\n Serial.print(\", \");\n Serial.print(engineOn);\n Serial.print(\", \");\n Serial.println(KnightRiderState);\n //function for hazard lights\n if(stateLT != 0 && stateRT != 0){\n \n leftLeds = NUM_LEDS_PART_B-1;\n rightLeds = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n\n for(int dot = 0; dot < NUM_LEDS_PART_B; dot++) {\n\n if(showSignalBigStrip == 1){\n ledsA[leftLeds] = turnColor;\n ledsA[rightLeds] = turnColor; \n }\n \n ledsB[0][dot] = turnColor;\n ledsB[1][dot] = turnColor;\n ledsB[2][dot] = turnColor; \n ledsB[3][dot] = turnColor;\n \n FastLED.show();\n //delay(delayTurnLedAnim);\n currentMillis = previousMillis = millis();\n while(previousMillis + delayTurnLedAnim >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n leftLeds--;\n rightLeds++;\n }\n \n //delay(delayTurnLedOff); \n currentMillis = previousMillis = millis();\n while(previousMillis + delayTurnLedOff >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n\n if(showSignalBigStrip == 1){\n \n leftLeds = NUM_LEDS_PART_B-1;\n for(int dot = 0; dot < NUM_LEDS_PART_B; dot++) {\n ledsA[leftLeds] = 0x000000; \n leftLeds--;\n } \n rightLeds = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n for(int dot = 0; dot < NUM_LEDS_PART_B; dot++) {\n ledsA[rightLeds] = 0x000000; \n rightLeds++;\n }\n \n }\n fill_solid(ledsB[0], NUM_LEDS_PART_B, CRGB::Black);\n fill_solid(ledsB[1], NUM_LEDS_PART_B, CRGB::Black);\n fill_solid(ledsB[2], NUM_LEDS_PART_B, CRGB::Black);\n fill_solid(ledsB[3], NUM_LEDS_PART_B, CRGB::Black);\n FastLED.show();\n \n //delay(delayTurnLedOff); \n currentMillis = previousMillis = millis();\n while(previousMillis + delayTurnLedOff >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n\n buttonStateL = digitalRead(buttonPinL); \n buttonStateR = digitalRead(buttonPinR);\n if(buttonStateL != HIGH || buttonStateR != HIGH){\n \n if(buttonStateL == HIGH){\n stateLT = 1;\n }else{\n stateLT = 0;\n gBrtL = 0;\n }\n \n if(buttonStateR == HIGH){\n stateRT = 1;\n }else{\n stateRT = 0;\n gBrtR = 0;\n }\n \n if(buttonStateL != HIGH && buttonStateR != HIGH){\n //delay(delayLedToDayLight); \n currentMillis = previousMillis = millis();\n while(previousMillis + delayLedToDayLight >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n } \n \n leftLeds = NUM_LEDS_PART_B-1;\n rightLeds = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n \n if(showSignalBigStrip == 1){\n tailLeft = NUM_LEDS_PART_B;\n tailRight = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n }else{\n tailLeft = halfOfLeds-1;\n tailRight = halfOfLeds;\n }\n }\n \n }\n\n //function for left turn lights\n }else if(stateLT != 0){\n \n if(KnightRiderState == HIGH){\n fill_solid(ledsB[1], NUM_LEDS_PART_B, CRGB::Black);\n fill_solid(ledsB[3], NUM_LEDS_PART_B, CRGB::Black);\n }\n \n leftLeds = NUM_LEDS_PART_B-1;\n for(int dot = 0; dot < NUM_LEDS_PART_B; dot++) {\n\n if(showSignalBigStrip == 1){\n ledsA[leftLeds] = turnColor; \n }\n\n ledsB[0][dot] = turnColor;\n ledsB[2][dot] = turnColor;\n \n FastLED.show();\n //delay(delayTurnLedAnim);\n currentMillis = previousMillis = millis();\n while(previousMillis + delayTurnLedAnim >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n leftLeds--;\n }\n \n //delay(delayTurnLedOff); \n currentMillis = previousMillis = millis();\n while(previousMillis + delayTurnLedOff >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n\n leftLeds = NUM_LEDS_PART_B-1;\n for(int dot = 0; dot < NUM_LEDS_PART_B; dot++) {\n if(showSignalBigStrip == 1){\n ledsA[leftLeds] = 0x000000; \n }\n ledsB[0][dot] = 0x000000;\n ledsB[2][dot] = 0x000000;\n leftLeds--;\n }\n\n FastLED.show();\n \n //delay(delayTurnLedOff); \n currentMillis = previousMillis = millis();\n while(previousMillis + delayTurnLedOff >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n\n stateLT++;\n if(stateLT >= nrAnimAfterOff && buttonStateL != HIGH){\n stateLT = 0;\n gBrtL = 0;\n //delay(delayLedToDayLight); \n currentMillis = previousMillis = millis();\n while(previousMillis + delayLedToDayLight >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n } \n leftLeds = NUM_LEDS_PART_B-1;\n if(showSignalBigStrip == 1){\n tailLeft = NUM_LEDS_PART_B;\n tailRight = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n }else{\n tailLeft = halfOfLeds-1;\n tailRight = halfOfLeds;\n }\n }\n\n //function for right turn lights\n }else if(stateRT != 0){\n \n if(KnightRiderState == HIGH){\n fill_solid(ledsB[0], NUM_LEDS_PART_B, CRGB::Black);\n fill_solid(ledsB[2], NUM_LEDS_PART_B, CRGB::Black);\n }\n \n rightLeds = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n for(int dot = 0; dot < NUM_LEDS_PART_B; dot++) {\n if(showSignalBigStrip == 1){\n ledsA[rightLeds] = turnColor; \n }\n\n ledsB[1][dot] = turnColor;\n ledsB[3][dot] = turnColor;\n \n FastLED.show();\n //delay(delayTurnLedAnim);\n currentMillis = previousMillis = millis();\n while(previousMillis + delayTurnLedAnim >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n rightLeds++;\n }\n \n //delay(delayTurnLedOff); \n currentMillis = previousMillis = millis();\n while(previousMillis + delayTurnLedOff >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n \n rightLeds = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n for(int dot = 0; dot < NUM_LEDS_PART_B; dot++) {\n if(showSignalBigStrip == 1){\n ledsA[rightLeds] = 0x000000; \n }\n \n ledsB[1][dot] = 0x000000;\n ledsB[3][dot] = 0x000000;\n \n rightLeds++;\n }\n \n FastLED.show();\n //delay(delayTurnLedOff); \n currentMillis = previousMillis = millis();\n while(previousMillis + delayTurnLedOff >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n\n stateRT++;\n if(stateRT >= nrAnimAfterOff && buttonStateR != HIGH){\n stateRT = 0;\n gBrtR = 0;\n //delay(delayLedToDayLight);\n currentMillis = previousMillis = millis();\n while(previousMillis + delayLedToDayLight >= currentMillis){\n TailAndBrake();\n FastLED.show();\n currentMillis = millis();\n }\n rightLeds = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n if(showSignalBigStrip == 1){\n tailLeft = NUM_LEDS_PART_B;\n tailRight = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n }else{\n tailLeft = halfOfLeds-1;\n tailRight = halfOfLeds; \n }\n }\n\n //function for kight rider and day lights\n }else{\n\n if(knightRiderOvrDayL == 1 && KnightRiderState == HIGH && engineOn == HIGH){\n engineOn = LOW;\n }\n \n if(TailLights == HIGH && engineOn == HIGH){\n maxBrtN = maxBrtNight;\n }else{\n maxBrtN = maxBrt;\n }\n\n if(stateLT == 0 && engineOn == HIGH){\n if(gBrtL <= maxBrtN){\n EVERY_N_MILLISECONDS( 1 ) { gBrtL++; }\n fill_solid( ledsB[2], NUM_LEDS_PART_B, CHSV(0,0,gBrtL));\n \n }else if(gBrtL >= maxBrtN){\n EVERY_N_MILLISECONDS( 1 ) { gBrtL--; }\n fill_solid( ledsB[2], NUM_LEDS_PART_B, CHSV(0,0,gBrtL));\n }\n }else{\n if(gBrtL > 0){\n EVERY_N_MILLISECONDS( 1 ) { gBrtL--; }\n fill_solid( ledsB[2], NUM_LEDS_PART_B, CHSV(0,0,gBrtL));\n }\n }\n \n if(stateRT == 0 && engineOn == HIGH){\n if(gBrtR <= maxBrtN){\n EVERY_N_MILLISECONDS( 1 ) { gBrtR++; }\n fill_solid( ledsB[3], NUM_LEDS_PART_B, CHSV(0,0,gBrtR));\n }else if(gBrtR >= maxBrtN){\n EVERY_N_MILLISECONDS( 1 ) { gBrtR--; }\n fill_solid( ledsB[3], NUM_LEDS_PART_B, CHSV(0,0,gBrtR));\n }\n }else{\n if(gBrtR > 0){\n EVERY_N_MILLISECONDS( 1 ) { gBrtR--; }\n fill_solid( ledsB[3], NUM_LEDS_PART_B, CHSV(0,0,gBrtR));\n }\n }\n \n if(KnightRiderState == HIGH && engineOn == LOW){\n if(knightRiderRainbow == 1){\n EVERY_N_MILLISECONDS( 20 ) { gHue++; }\n }\n fadeToBlackBy( ledsB[0], NUM_LEDS_PART_B, knightRiderTail);\n fadeToBlackBy( ledsB[1], NUM_LEDS_PART_B, knightRiderTail);\n fadeToBlackBy( ledsB[2], NUM_LEDS_PART_B, knightRiderTail);\n fadeToBlackBy( ledsB[3], NUM_LEDS_PART_B, knightRiderTail);\n int pos = beatsin16( knightRiderSpeed, 0, NUM_LEDS_PART_B-1 );\n ledsB[0][pos] += CHSV( gHue, 255, 192);\n ledsB[1][pos] += CHSV( gHue, 255, 192);\n ledsB[2][pos] += CHSV( gHue, 255, 192);\n ledsB[3][pos] += CHSV( gHue, 255, 192);\n KnightRiderToOff = 1;\n }else{\n if(KnightRiderToOff == 1){\n fill_solid(ledsB[0], NUM_LEDS_PART_B, CRGB::Black);\n fill_solid(ledsB[1], NUM_LEDS_PART_B, CRGB::Black);\n fill_solid(ledsB[2], NUM_LEDS_PART_B, CRGB::Black);\n fill_solid(ledsB[3], NUM_LEDS_PART_B, CRGB::Black);\n if(showSignalBigStrip == 1){\n tailLeft = NUM_LEDS_PART_B;\n tailRight = NUM_LEDS_PART_A-NUM_LEDS_PART_B;\n }else{\n tailLeft = halfOfLeds-1;\n tailRight = halfOfLeds; \n }\n KnightRiderToOff = 0;\n }\n }\n\n TailAndBrake();\n FastLED.show();\n }\n}\n\n//function for Brake lights, tail lights\nvoid TailAndBrake(){\n \n Brake = digitalRead(buttonPinBrake);\n TailLights = digitalRead(buttonPinTailLights);\n \n if(TailLights == HIGH && Brake == LOW){\n \n if(stateLT == 0 && stateRT == 0){\n \n if(tailLeft >= 0){\n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailLeft]=CHSV(0,255,maxBrtTailLights);\n if(showTailBrakeSmalStrip == 1 && tailLeft < NUM_LEDS_PART_B){\n tailLeftSmall = map(tailLeft,NUM_LEDS_PART_B-1,0,0,NUM_LEDS_PART_B-1);\n ledsB[0][tailLeftSmall]=CHSV(0,255,maxBrtTailLights); \n }\n tailLeft--;\n }\n }\n \n if(tailRight < NUM_LEDS_PART_A){\n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailRight]=CHSV(0,255,maxBrtTailLights);\n if(showTailBrakeSmalStrip == 1 && tailRight > NUM_LEDS_PART_A-NUM_LEDS_PART_B-1){\n tailRightSmall = map(tailRight,NUM_LEDS_PART_A-NUM_LEDS_PART_B-1,NUM_LEDS_PART_A-1,0,NUM_LEDS_PART_B-1);\n ledsB[1][tailRightSmall]=CHSV(0,255,maxBrtTailLights); \n }\n tailRight++;\n }\n }\n \n }else if(stateLT != 0 && stateRT != 0){\n\n if(showSignalBigStrip == 1){\n if(tailLeft >= NUM_LEDS_PART_B){\n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailLeft]=CHSV(0,255,maxBrtTailLights);\n tailLeft--;\n }\n }\n \n if(tailRight < NUM_LEDS_PART_A-NUM_LEDS_PART_B){\n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailRight]=CHSV(0,255,maxBrtTailLights);\n tailRight++;\n }\n } \n }else{\n if(tailLeft >= 0){\n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailLeft]=CHSV(0,255,maxBrtTailLights);\n tailLeft--;\n }\n }\n \n if(tailRight < NUM_LEDS_PART_A){\n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailRight]=CHSV(0,255,maxBrtTailLights);\n tailRight++;\n }\n }\n }\n \n }else{\n \n if(stateLT != 0){\n\n if(showSignalBigStrip == 1){\n if(tailLeft >= NUM_LEDS_PART_B){ \n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailLeft]=CHSV(0,255,maxBrtTailLights);\n tailLeft--;\n }\n } \n }else{\n if(tailLeft >= 0){ \n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailLeft]=CHSV(0,255,maxBrtTailLights);\n tailLeft--;\n }\n }\n }\n\n if(tailRight < NUM_LEDS_PART_A){ \n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailRight]=CHSV(0,255,maxBrtTailLights);\n if(showTailBrakeSmalStrip == 1 && tailRight > NUM_LEDS_PART_A-NUM_LEDS_PART_B-1){\n tailRightSmall = map(tailRight,NUM_LEDS_PART_A-NUM_LEDS_PART_B-1,NUM_LEDS_PART_A-1,0,NUM_LEDS_PART_B-1);\n ledsB[1][tailRightSmall]=CHSV(0,255,maxBrtTailLights); \n }\n tailRight++;\n }\n }\n }\n \n if(stateRT != 0){\n\n if(tailLeft >= 0){ \n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailLeft]=CHSV(0,255,maxBrtTailLights);\n if(showTailBrakeSmalStrip == 1 && tailLeft < NUM_LEDS_PART_B){\n tailLeftSmall = map(tailLeft,NUM_LEDS_PART_B-1,0,0,NUM_LEDS_PART_B-1);\n ledsB[0][tailLeftSmall]=CHSV(0,255,maxBrtTailLights); \n }\n tailLeft--;\n }\n }\n\n if(showSignalBigStrip == 1){\n if(tailRight < NUM_LEDS_PART_A-NUM_LEDS_PART_B){ \n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailRight]=CHSV(0,255,maxBrtTailLights);\n tailRight++;\n }\n } \n }else{\n if(tailRight < NUM_LEDS_PART_A){ \n EVERY_N_MILLISECONDS( tailDelay ) {\n ledsA[tailRight]=CHSV(0,255,maxBrtTailLights);\n tailRight++;\n }\n }\n }\n }\n } \n }else if(Brake == HIGH){\n \n if(stateLT == 0 && stateRT == 0){\n fill_solid( ledsA, NUM_LEDS_PART_A, CHSV(0,255,maxBrtBrake));\n if(showTailBrakeSmalStrip == 1){\n fill_solid( ledsB[0], NUM_LEDS_PART_B, CHSV(0,255,maxBrtBrake));\n fill_solid( ledsB[1], NUM_LEDS_PART_B, CHSV(0,255,maxBrtBrake)); \n }\n \n }else if(stateLT != 0 && stateRT != 0){\n\n if(showSignalBigStrip == 1){\n for(int i = NUM_LEDS_PART_B; i < halfOfLeds; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n } \n for(int i = halfOfLeds; i < NUM_LEDS_PART_A-NUM_LEDS_PART_B; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n } \n }else{\n for(int i = 0; i < halfOfLeds; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n } \n for(int i = halfOfLeds; i < NUM_LEDS_PART_A; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n }\n }\n \n }else{\n \n if(stateLT != 0){\n \n if(showSignalBigStrip == 1){\n for(int i = NUM_LEDS_PART_B; i < halfOfLeds; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n }\n for(int i = halfOfLeds; i < NUM_LEDS_PART_A; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n } \n }else{\n for(int i = 0; i < halfOfLeds; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n }\n for(int i = halfOfLeds; i < NUM_LEDS_PART_A; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n }\n }\n\n if(showTailBrakeSmalStrip == 1){\n fill_solid( ledsB[1], NUM_LEDS_PART_B, CHSV(0,255,maxBrtBrake)); \n }\n }\n if(stateRT != 0){\n \n if(showSignalBigStrip == 1){\n for(int i = halfOfLeds; i < NUM_LEDS_PART_A-NUM_LEDS_PART_B; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n }\n for(int i = 0; i < halfOfLeds; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n }\n }else{\n for(int i = halfOfLeds; i < NUM_LEDS_PART_A; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n }\n for(int i = 0; i < halfOfLeds; i++){\n ledsA[i] = CHSV(0,255,maxBrtBrake);\n }\n\n }\n if(showTailBrakeSmalStrip == 1){\n fill_solid( ledsB[0], NUM_LEDS_PART_B, CHSV(0,255,maxBrtBrake));\n }\n }\n \n }\n \n tailLeft = halfOfLeds-1;\n tailRight = halfOfLeds;\n brakeToOffL = 1;\n brakeToOffR = 1;\n \n }else{\n \n if(tailLeft < halfOfLeds-1){\n EVERY_N_MILLISECONDS( tailDelay ) {\n tailLeft++;\n ledsA[tailLeft]=CHSV(0,0,0);\n if(showTailBrakeSmalStrip == 1 && tailLeft < NUM_LEDS_PART_B){\n tailLeftSmall = map(tailLeft,NUM_LEDS_PART_B-1,0,0,NUM_LEDS_PART_B-1);\n ledsB[0][tailLeftSmall]=CHSV(0,0,0);\n }\n }\n }else{\n if(stateLT != 0){\n if(brakeToOffL == 1){\n if(showSignalBigStrip == 1){\n for(int i = NUM_LEDS_PART_B; i < halfOfLeds; i++){\n ledsA[i] = CHSV(0,0,0);\n } \n }else{\n for(int i = 0; i < halfOfLeds; i++){\n ledsA[i] = CHSV(0,0,0);\n }\n }\n brakeToOffL = 0;\n }\n }else{\n for(int i = 0; i < halfOfLeds; i++){\n ledsA[i] = CHSV(0,0,0);\n }\n if(KnightRiderState == LOW){\n fill_solid( ledsB[0], NUM_LEDS_PART_B, CHSV(0,0,0));\n }\n }\n }\n\n if(tailRight > halfOfLeds){\n EVERY_N_MILLISECONDS( tailDelay ) {\n tailRight--;\n ledsA[tailRight]=CHSV(0,0,0);\n if(showTailBrakeSmalStrip == 1 && tailRight > NUM_LEDS_PART_A-NUM_LEDS_PART_B-1){\n tailRightSmall = map(tailRight,NUM_LEDS_PART_A-NUM_LEDS_PART_B-1,NUM_LEDS_PART_A-1,0,NUM_LEDS_PART_B-1);\n ledsB[1][tailRightSmall]=CHSV(0,0,0);\n }\n \n } \n }else{\n if(stateRT != 0){\n if(brakeToOffR == 1){\n if(showSignalBigStrip == 1){\n for(int i = halfOfLeds; i < NUM_LEDS_PART_A-NUM_LEDS_PART_B; i++){\n ledsA[i] = CHSV(0,0,0);\n } \n }else{\n for(int i = halfOfLeds; i < NUM_LEDS_PART_A; i++){\n ledsA[i] = CHSV(0,0,0);\n }\n }\n brakeToOffR = 0;\n }\n }else{\n for(int i = halfOfLeds; i < halfOfLeds*2; i++){\n ledsA[i] = CHSV(0,0,0);\n }\n if(KnightRiderState == LOW){\n fill_solid( ledsB[1], NUM_LEDS_PART_B, CHSV(0,0,0)); \n }\n }\n }\n } \n}\n\n//function for left signal interrupt\nvoid btnPressL(){\n stateLT = 1;\n for(int nr = 0; nr < 1500; nr++) { \n buttonStateR = digitalRead(buttonPinR);\n if(buttonStateR == 1){\n stateRT = 1; \n }\n } \n}\n\n//function for right signal interrupt\nvoid btnPressR(){\n stateRT = 1;\n for(int nr = 0; nr < 1500; nr++) { \n buttonStateL = digitalRead(buttonPinL); \n if(buttonStateL == 1){\n stateLT = 1;\n }\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Usama Shafiq\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-half\", \"id\": \"bb1\", \"top\": -214.2, \"left\": 156.4, \"attrs\": {} },\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0.6, \"left\": -0.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring1\",\n \"top\": -513.02,\n \"left\": 27.56,\n \"attrs\": { \"pixels\": \"20\" }\n },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring3\",\n \"top\": -339.96,\n \"left\": -68.31,\n \"attrs\": { \"pixels\": \"4\" }\n },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring4\",\n \"top\": -330.36,\n \"left\": 210.09,\n \"attrs\": { \"pixels\": \"4\" }\n },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring5\",\n \"top\": -368.76,\n \"left\": 152.49,\n \"attrs\": { \"pixels\": \"4\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": -52.8,\n \"left\": 201.05,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": -52.8,\n \"left\": 191.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": -52.8,\n \"left\": 181.85,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r4\",\n \"top\": -52.8,\n \"left\": 172.25,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r5\",\n \"top\": -52.8,\n \"left\": 162.65,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r6\",\n \"top\": -52.8,\n \"left\": 153.05,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n },\n { \"type\": \"wokwi-dip-switch-8\", \"id\": \"sw1\", \"top\": -147.3, \"left\": 174.3, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r7\",\n \"top\": -24,\n \"left\": 133.85,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r8\",\n \"top\": -24,\n \"left\": 124.25,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r9\",\n \"top\": -24,\n \"left\": 114.65,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r10\",\n \"top\": -24,\n \"left\": 105.05,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r11\",\n \"top\": -24,\n \"left\": 95.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring2\",\n \"top\": -378.36,\n \"left\": -10.71,\n \"attrs\": { \"pixels\": \"4\" }\n },\n { \"type\": \"wokwi-vcc\", \"id\": \"vcc1\", \"top\": -373.64, \"left\": 326.4, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"uno:2\", \"bb1:6b.g\", \"magenta\", [ \"v0\" ] ],\n [ \"uno:3\", \"bb1:5b.g\", \"gray\", [ \"v0\" ] ],\n [ \"uno:4\", \"bb1:4b.g\", \"limegreen\", [ \"v0\" ] ],\n [ \"uno:5\", \"bb1:3b.g\", \"cyan\", [ \"v0\" ] ],\n [ \"uno:6\", \"bb1:2b.g\", \"yellow\", [ \"v0\" ] ],\n [ \"uno:7\", \"bb1:1b.g\", \"purple\", [ \"v0\" ] ],\n [ \"r6:2\", \"r5:2\", \"green\", [ \"h0\" ] ],\n [ \"bb1:tp.1\", \"bb1:1t.a\", \"red\", [ \"v0.3\", \"h-8\" ] ],\n [ \"bb1:2t.b\", \"bb1:1t.b\", \"green\", [ \"v0\" ] ],\n [ \"bb1:3t.a\", \"bb1:2t.a\", \"green\", [ \"v0\" ] ],\n [ \"bb1:3t.b\", \"bb1:4t.b\", \"green\", [ \"v0\" ] ],\n [ \"bb1:4t.a\", \"bb1:5t.a\", \"green\", [ \"v0\" ] ],\n [ \"bb1:5t.b\", \"bb1:6t.b\", \"green\", [ \"v0\" ] ],\n [ \"uno:GND.2\", \"bb1:bn.25\", \"black\", [ \"v19.1\", \"h128.7\" ] ],\n [ \"uno:5V\", \"bb1:bp.24\", \"red\", [ \"v28.7\", \"h109.4\" ] ],\n [ \"ring5:DIN\", \"r7:1\", \"violet\", [ \"v48\", \"h-28.8\" ] ],\n [ \"ring2:DIN\", \"r8:1\", \"gold\", [ \"v57.6\", \"h115.2\" ] ],\n [ \"ring4:DIN\", \"r9:1\", \"gray\", [ \"v19.2\", \"h-76.8\" ] ],\n [ \"ring3:DIN\", \"r10:1\", \"orange\", [ \"v28.8\", \"h144\" ] ],\n [ \"ring1:DIN\", \"r11:1\", \"blue\", [ \"v0\" ] ],\n [ \"bb1:tp.25\", \"bb1:bp.25\", \"red\", [ \"v0.3\", \"h40\", \"v172.8\" ] ],\n [ \"bb1:tn.25\", \"bb1:bn.25\", \"black\", [ \"v-0.1\", \"h49.6\", \"v192\" ] ],\n [ \"r1:1\", \"bb1:6b.h\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"bb1:bn.5\", \"\", [ \"$bb\" ] ],\n [ \"r2:1\", \"bb1:5b.h\", \"\", [ \"$bb\" ] ],\n [ \"r2:2\", \"bb1:bn.4\", \"\", [ \"$bb\" ] ],\n [ \"r3:1\", \"bb1:4b.h\", \"\", [ \"$bb\" ] ],\n [ \"r3:2\", \"bb1:bn.3\", \"\", [ \"$bb\" ] ],\n [ \"r4:1\", \"bb1:3b.h\", \"\", [ \"$bb\" ] ],\n [ \"r4:2\", \"bb1:bn.2\", \"\", [ \"$bb\" ] ],\n [ \"r5:1\", \"bb1:2b.h\", \"\", [ \"$bb\" ] ],\n [ \"r5:2\", \"bb1:bn.1\", \"\", [ \"$bb\" ] ],\n [ \"r6:1\", \"bb1:1b.h\", \"\", [ \"$bb\" ] ],\n [ \"sw1:1a\", \"bb1:1b.f\", \"\", [ \"$bb\" ] ],\n [ \"sw1:2a\", \"bb1:2b.f\", \"\", [ \"$bb\" ] ],\n [ \"sw1:3a\", \"bb1:3b.f\", \"\", [ \"$bb\" ] ],\n [ \"sw1:4a\", \"bb1:4b.f\", \"\", [ \"$bb\" ] ],\n [ \"sw1:5a\", \"bb1:5b.f\", \"\", [ \"$bb\" ] ],\n [ \"sw1:6a\", \"bb1:6b.f\", \"\", [ \"$bb\" ] ],\n [ \"sw1:7a\", \"bb1:7b.f\", \"\", [ \"$bb\" ] ],\n [ \"sw1:8a\", \"bb1:8b.f\", \"\", [ \"$bb\" ] ],\n [ \"sw1:8b\", \"bb1:8t.c\", \"\", [ \"$bb\" ] ],\n [ \"sw1:7b\", \"bb1:7t.c\", \"\", [ \"$bb\" ] ],\n [ \"sw1:6b\", \"bb1:6t.c\", \"\", [ \"$bb\" ] ],\n [ \"sw1:5b\", \"bb1:5t.c\", \"\", [ \"$bb\" ] ],\n [ \"sw1:4b\", \"bb1:4t.c\", \"\", [ \"$bb\" ] ],\n [ \"sw1:3b\", \"bb1:3t.c\", \"\", [ \"$bb\" ] ],\n [ \"sw1:2b\", \"bb1:2t.c\", \"\", [ \"$bb\" ] ],\n [ \"sw1:1b\", \"bb1:1t.c\", \"\", [ \"$bb\" ] ],\n [ \"ring4:GND\", \"bb1:tn.5\", \"black\", [ \"v0\" ] ],\n [ \"ring5:GND\", \"ring4:GND\", \"black\", [ \"v0\" ] ],\n [ \"ring1:GND\", \"ring5:GND\", \"black\", [ \"v0\" ] ],\n [ \"ring2:GND\", \"ring4:GND\", \"black\", [ \"v0\" ] ],\n [ \"ring3:GND\", \"bb1:tn.1\", \"black\", [ \"v0\" ] ],\n [ \"ring4:VCC\", \"vcc1:VCC\", \"red\", [ \"v9.6\", \"h67.2\" ] ],\n [ \"ring5:VCC\", \"ring4:VCC\", \"red\", [ \"v67.2\", \"h28.8\" ] ],\n [ \"ring1:VCC\", \"ring5:VCC\", \"red\", [ \"v67.2\", \"h67.2\" ] ],\n [ \"ring2:VCC\", \"ring1:VCC\", \"red\", [ \"v38.4\", \"h76.8\" ] ],\n [ \"ring3:VCC\", \"ring2:VCC\", \"red\", [ \"v19.2\", \"h48\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for LED sequence", + "input": "void setup() {\npinMode(13, OUTPUT);\npinMode(7, OUTPUT);\npinMode(1, OUTPUT);\n}\n\nvoid loop() {\ndigitalWrite(13, HIGH);\ndelay(2000);\ndigitalWrite(7, HIGH);\ndelay(2000);\ndigitalWrite(1, HIGH);\ndelay(1000);\n\ndigitalWrite(13, LOW);\ndigitalWrite(7, LOW);\ndigitalWrite(1, LOW);\n\ndelay(1000);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -90, \"left\": 99.8, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -99.6,\n \"left\": 138.2,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": -109.2,\n \"left\": 186.2,\n \"attrs\": { \"color\": \"yellow\" }\n }\n ],\n \"connections\": [\n [ \"led1:C\", \"uno:GND.1\", \"green\", [ \"v0\" ] ],\n [ \"led1:A\", \"uno:13\", \"green\", [ \"v9.6\", \"h0\", \"v9.6\" ] ],\n [ \"led2:C\", \"led1:C\", \"green\", [ \"v9.6\", \"h-38\" ] ],\n [ \"led2:A\", \"uno:7\", \"green\", [ \"v0\" ] ],\n [ \"led3:C\", \"led2:C\", \"green\", [ \"v0\" ] ],\n [ \"led3:A\", \"uno:4\", \"green\", [ \"v0\" ] ],\n [ \"uno:4\", \"uno:1\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for window control using arduino", + "input": "#include \n#include \"Button.h\"\n#include \"ServoMotor.h\"\n#include \"Potentiometer.h\"\n#include \"MsgService.h\"\n#include \"Lcd.h\"\n\n#define button_pin 2\n#define pot_pin A0\n#define servo_pin 10\n\nint lastPercentage = 0;\nint percentage = 0;\nint temperature = 0;\n\nButton* btn;\nServoMotor* window;\nPotentiometer* potentiometer;\nLcd* lcd;\n\nenum {automatic, manual} state ;\n\nvoid setup() {\n // put your setup code here, to run once:\n MsgService.init();\n \n btn = new Button(button_pin);\n window = new ServoMotor(servo_pin);\n potentiometer = new Potentiometer(pot_pin);\n lcd = new Lcd(0x27,20,4);\n lcd->init();\n\n window->openPercentage(0);\n state = automatic;\n\n lcd->setCursorTo(3,0);\n lcd->print(\"state:Automatic\");\n Serial.println(\"Hello Friend!\");\n}\nvoid loop() {\n \n // put your main code here, to run repeatedly:\n bool buttonIsPressed = btn->isPressed();\n if(MsgService.isMsgAvailable()){\n Msg* msg = MsgService.receiveMsg();\n String tag = msg->getContent().substring(0,1);\n String value = msg->getContent().substring(2);\n\n if(tag == \"T\"){\n temperature = value.toInt();\n\n }else if(tag == \"S\"){\n if(value == \"automatic\"){\n state = automatic;\n }else if(value == \"manual\"){\n state = manual;\n }else{\n lcd->print(\"State is not set properly\");\n }\n\n }else if(tag == \"P\"){\n percentage = value.toInt();\n }else{\n Serial.println(\"I didn't understand!\");\n } \n }\n \n switch(state){\n\n case automatic:\n lcd->updateState(\"Automatic\"); \n lcd->updatePercentage(percentage); \n MsgService.sendMsg(\"S:automatic\");\n\n if(buttonIsPressed){\n state = manual;\n }else{\n lcd->setCursorTo(0, 2);\n lcd->print(\" \");\n if(percentage != lastPercentage){\n lastPercentage = percentage;\n lcd->updatePercentage(lastPercentage);\n window->openPercentage(lastPercentage);\n }\n }\n break;\n\n case manual:\n \n if(buttonIsPressed){\n state = automatic;\n lcd->clearScreen();\n }else{\n lcd->updateState(\"Manual\");\n lcd->updatePercentage(lastPercentage);\n lcd->updateTemp(temperature);\n MsgService.sendMsg(\"S:manual\");\n \n int potPercentage = potentiometer->percentageValue();\n\n if(potPercentage != lastPercentage){\n lastPercentage = potPercentage;\n lcd->updatePercentage(lastPercentage);\n window->openPercentage(lastPercentage);\n String percentMsg = \"P:\" + String(lastPercentage);\n MsgService.sendMsg(percentMsg);\n } \n }\n }\n delay(200);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Keni Tafili\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-half\", \"id\": \"bb1\", \"top\": -60.6, \"left\": 146.8, \"attrs\": {} },\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": -57, \"left\": -231, \"attrs\": {} },\n { \"type\": \"wokwi-servo\", \"id\": \"servo1\", \"top\": -194, \"left\": 96, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot1\", \"top\": -174.1, \"left\": 374.2, \"attrs\": {} },\n {\n \"type\": \"wokwi-lcd2004\",\n \"id\": \"lcd1\",\n \"top\": 198.4,\n \"left\": 149.6,\n \"attrs\": { \"pins\": \"i2c\" }\n },\n {\n \"type\": \"wokwi-pushbutton-6mm\",\n \"id\": \"btn1\",\n \"top\": 29.3,\n \"left\": 339.5,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 100.8,\n \"left\": 335.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n }\n ],\n \"connections\": [\n [ \"uno:GND.2\", \"bb1:bn.1\", \"black\", [ \"v28.7\", \"h243.9\" ] ],\n [ \"uno:5V\", \"bb1:bp.1\", \"red\", [ \"v47.9\", \"h243.8\", \"v-57.6\" ] ],\n [ \"bb1:bp.15\", \"bb1:19b.j\", \"red\", [ \"v0\" ] ],\n [ \"bb1:21t.a\", \"uno:2\", \"gold\", [ \"v-9.6\", \"h-297.6\" ] ],\n [ \"servo1:PWM\", \"uno:10\", \"green\", [ \"h0\" ] ],\n [ \"servo1:V+\", \"bb1:bp.3\", \"purple\", [ \"h-38.4\", \"v48.1\", \"h144\", \"v9.6\" ] ],\n [ \"servo1:GND\", \"bb1:bn.2\", \"black\", [ \"h-57.6\", \"v76.8\", \"h153.6\" ] ],\n [ \"pot1:GND\", \"bb1:bn.21\", \"black\", [ \"v0\" ] ],\n [ \"pot1:VCC\", \"bb1:bp.24\", \"red\", [ \"v0\" ] ],\n [ \"pot1:SIG\", \"uno:A0\", \"green\", [ \"v297.6\", \"h-436.2\" ] ],\n [ \"lcd1:GND\", \"bb1:bn.4\", \"black\", [ \"h-28.8\", \"v-57.6\", \"h86.4\" ] ],\n [ \"lcd1:VCC\", \"bb1:bp.5\", \"red\", [ \"h-19.2\", \"v-86.3\", \"h86.4\", \"v-27.9\" ] ],\n [ \"lcd1:SDA\", \"uno:A4\", \"orange\", [ \"h-134.4\", \"v-28.6\" ] ],\n [ \"lcd1:SCL\", \"uno:A5\", \"blue\", [ \"h-115.2\", \"v9.9\" ] ],\n [ \"btn1:1.l\", \"bb1:21t.e\", \"\", [ \"$bb\" ] ],\n [ \"btn1:2.l\", \"bb1:19t.e\", \"\", [ \"$bb\" ] ],\n [ \"btn1:1.r\", \"bb1:21b.f\", \"\", [ \"$bb\" ] ],\n [ \"btn1:2.r\", \"bb1:19b.f\", \"\", [ \"$bb\" ] ],\n [ \"r1:1\", \"bb1:21b.h\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"bb1:bn.17\", \"\", [ \"$bb\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Simple LED blink using arduino", + "input": "int led = 11;\n\nvoid setup() { \n pinMode(led, OUTPUT); \n}\n\nvoid loop() {\n digitalWrite(led, HIGH); \n delay(1000); \n digitalWrite(led, LOW); \n delay(1000); \n}", + "output": "{\n \"version\": 1,\n \"author\": \"Julian Manders-Jones\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard\", \"id\": \"bb1\", \"top\": 93, \"left\": 70, \"attrs\": {} },\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": -124.2, \"left\": 354.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": 164.8,\n \"left\": 589.8,\n \"rotate\": 180,\n \"attrs\": { \"color\": \"red\", \"flip\": \"\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 147.95,\n \"left\": 499.2,\n \"attrs\": { \"value\": \"1000\" }\n }\n ],\n \"connections\": [\n [ \"bb1:55t.a\", \"bb1:tn.45\", \"green\", [ \"v0\" ] ],\n [ \"bb1:54t.c\", \"bb1:49t.c\", \"green\", [ \"v0\" ] ],\n [ \"uno:11\", \"bb1:43t.a\", \"gold\", [ \"v0\" ] ],\n [ \"r1:1\", \"bb1:43t.b\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"bb1:49t.b\", \"\", [ \"$bb\" ] ],\n [ \"led1:A\", \"bb1:54t.d\", \"\", [ \"$bb\" ] ],\n [ \"led1:C\", \"bb1:55t.d\", \"\", [ \"$bb\" ] ],\n [ \"uno:GND.3\", \"bb1:tn.38\", \"black\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for relay control", + "input": "int i = 0;\n\nvoid setup() {\n pinMode(2, OUTPUT);\n pinMode(3, OUTPUT);\n pinMode(4, INPUT_PULLUP);\n pinMode(5, INPUT_PULLUP);\n pinMode(6, INPUT_PULLUP);\n}\n\nvoid loop() {\n if (digitalRead(4) == 0)\n {\n digitalWrite(2, HIGH);\n }\n else if (digitalRead(5) == 0)\n {\n digitalWrite(2, HIGH);\n digitalWrite(3, HIGH);\n }\n else if (digitalRead(6) == 0)\n {\n digitalWrite(3, HIGH);\n }\n delay(50);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"\u0411\u0430\u0440\u0441\u0443\u043a \u0418\u0432\u0430\u043d\u043e\u0432\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-nano\", \"id\": \"nano\", \"top\": 4.8, \"left\": -58.1, \"attrs\": {} },\n { \"type\": \"wokwi-relay-module\", \"id\": \"relay1\", \"top\": -86.2, \"left\": 96, \"attrs\": {} },\n { \"type\": \"wokwi-relay-module\", \"id\": \"relay2\", \"top\": 105.8, \"left\": 96, \"attrs\": {} },\n {\n \"type\": \"wokwi-pushbutton-6mm\",\n \"id\": \"btn1\",\n \"top\": -98.2,\n \"left\": -124.8,\n \"attrs\": { \"color\": \"green\", \"key\": \"(\" }\n },\n {\n \"type\": \"wokwi-pushbutton-6mm\",\n \"id\": \"btn2\",\n \"top\": -98.2,\n \"left\": -86.4,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-pushbutton-6mm\",\n \"id\": \"btn3\",\n \"top\": -98.2,\n \"left\": -48,\n \"attrs\": { \"color\": \"green\" }\n },\n { \"type\": \"wokwi-vcc\", \"id\": \"vcc1\", \"top\": -133.64, \"left\": 249.6, \"attrs\": {} },\n { \"type\": \"wokwi-junction\", \"id\": \"j1\", \"top\": -72, \"left\": 350.4, \"attrs\": {} },\n { \"type\": \"wokwi-junction\", \"id\": \"j2\", \"top\": 120, \"left\": 350.4, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"relay1:GND\", \"nano:GND.2\", \"black\", [ \"h0\" ] ],\n [ \"relay1:IN\", \"nano:2\", \"green\", [ \"h-38.4\", \"v9.4\" ] ],\n [ \"nano:GND.1\", \"relay2:GND\", \"black\", [ \"v67.2\" ] ],\n [ \"relay2:IN\", \"nano:3\", \"green\", [ \"h-163.2\", \"v-163.4\", \"h115.2\" ] ],\n [ \"relay2:VCC\", \"nano:5V\", \"red\", [ \"h0\" ] ],\n [ \"relay1:VCC\", \"relay2:VCC\", \"red\", [ \"h-19.2\", \"v57.6\", \"h38.4\", \"v86.4\", \"h-19.2\" ] ],\n [ \"relay1:COM\", \"relay2:COM\", \"black\", [ \"h39.6\", \"v190.6\" ] ],\n [ \"relay2:GND\", \"relay2:COM\", \"black\", [ \"h-19.2\", \"v47.6\", \"h172.8\", \"v-48\" ] ],\n [ \"btn2:1.r\", \"btn3:1.r\", \"black\", [ \"v-9.6\", \"h39.2\" ] ],\n [ \"btn1:1.r\", \"btn2:1.r\", \"black\", [ \"v-9.6\", \"h39.2\" ] ],\n [ \"btn3:1.r\", \"nano:GND.2\", \"black\", [ \"v-9.6\", \"h87.2\" ] ],\n [ \"btn3:2.r\", \"nano:4\", \"green\", [ \"h0\" ] ],\n [ \"btn2:2.r\", \"nano:5\", \"green\", [ \"h0.8\", \"v10\", \"h86.4\" ] ],\n [ \"btn1:2.r\", \"nano:6\", \"green\", [ \"h0.8\", \"v19.6\", \"h115.2\" ] ],\n [ \"relay1:NO\", \"vcc1:VCC\", \"red\", [ \"h0\" ] ],\n [ \"relay2:NO\", \"vcc1:VCC\", \"red\", [ \"h49.2\", \"v-193.8\" ] ],\n [ \"relay2:NC\", \"j2:J\", \"orange\", [ \"v-1.2\", \"h145.2\" ] ],\n [ \"j1:J\", \"relay1:NC\", \"orange\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Traffic light control", + "input": "int Knop = A3;\nint RED_LED = A0;\nint GREEN_LED = A2;\nint YELLOW_LED = A1;\n\ntypedef enum {Rood, Groen, Geel} states;\nstatic states state = Rood;\n\n// Constante voor de duur van geel\nconst int geelDuur = 4000; \nint geelStartTijd = 0; // Tijd in milliseconden voor geel\n\nvoid setup() {\n pinMode(Knop, INPUT_PULLUP);\n pinMode(RED_LED, OUTPUT);\n pinMode(GREEN_LED, OUTPUT);\n pinMode(YELLOW_LED, OUTPUT);\n\n // Zet beginwaarden voor LEDs\n digitalWrite(RED_LED, HIGH); // Start met rood aan\n digitalWrite(GREEN_LED, LOW);\n digitalWrite(YELLOW_LED, LOW);\n}\n\nvoid loop() {\n // Lees de waarde van de knop\n int knopStatus = digitalRead(Knop);\n\n switch (state) {\n case Rood:\n if (knopStatus == LOW) { // Knop ingedrukt (LOW vanwege INPUT_PULLUP)\n state = Groen;\n digitalWrite(RED_LED, LOW);\n digitalWrite(GREEN_LED, HIGH);\n digitalWrite(YELLOW_LED, LOW);\n }\n break;\n\n case Groen:\n if (knopStatus == HIGH) { // Knop losgelaten\n state = Geel;\n geelStartTijd = millis(); // Sla de huidige tijd op\n digitalWrite(RED_LED, LOW);\n digitalWrite(GREEN_LED, LOW);\n digitalWrite(YELLOW_LED, HIGH);\n }\n break;\n\n case Geel:\n // Controleer of de huidige tijd 3 seconden na geelStartTijd is\n if ((millis() - geelStartTijd) >= geelDuur) {\n state = Rood;\n digitalWrite(RED_LED, HIGH);\n digitalWrite(GREEN_LED, LOW);\n digitalWrite(YELLOW_LED, LOW);\n }\n break;\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": -105, \"left\": -0.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-rgb-led\",\n \"id\": \"rgb1\",\n \"top\": 90.4,\n \"left\": -114.1,\n \"attrs\": { \"common\": \"cathode\" }\n },\n {\n \"type\": \"wokwi-rgb-led\",\n \"id\": \"rgb2\",\n \"top\": 157.6,\n \"left\": -114.1,\n \"attrs\": { \"common\": \"cathode\" }\n },\n {\n \"type\": \"wokwi-rgb-led\",\n \"id\": \"rgb3\",\n \"top\": 224.8,\n \"left\": -114.1,\n \"attrs\": { \"common\": \"cathode\" }\n },\n {\n \"type\": \"wokwi-slide-switch\",\n \"id\": \"sw1\",\n \"top\": 167.6,\n \"left\": -6.5,\n \"attrs\": { \"bounce\": \"0\", \"value\": \"0\" }\n }\n ],\n \"connections\": [\n [ \"sw1:2\", \"uno:A3\", \"green\", [ \"v19.2\", \"h192.1\" ] ],\n [ \"sw1:3\", \"uno:5V\", \"red\", [ \"v9.6\", \"h134.6\" ] ],\n [ \"uno:GND.2\", \"sw1:1\", \"black\", [ \"v143.9\", \"h-159.3\" ] ],\n [ \"rgb1:COM\", \"rgb2:COM\", \"black\", [ \"v-0.4\", \"h-28.7\", \"v67.2\" ] ],\n [ \"rgb2:COM\", \"rgb3:COM\", \"black\", [ \"v-0.4\", \"h-28.7\", \"v67.2\" ] ],\n [ \"uno:GND.3\", \"rgb1:COM\", \"black\", [ \"v220.7\", \"h-303.2\", \"v-163.2\" ] ],\n [ \"rgb1:R\", \"uno:A0\", \"red\", [ \"v19.2\", \"h316.8\" ] ],\n [ \"rgb3:G\", \"uno:A2\", \"green\", [ \"v28.8\", \"h308.5\" ] ],\n [ \"rgb2:R\", \"uno:A1\", \"gold\", [ \"v19.2\", \"h76.8\", \"v38.4\", \"h240\" ] ],\n [ \"rgb2:G\", \"uno:A1\", \"gold\", [ \"v9.6\", \"h68.5\", \"v38.4\", \"h220.8\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for motor control", + "input": "#include \n#define thermocouple A2\n#define PRIV 13\n#define ENTER 12\n#define Next 11\n#define Limit 10\n#define Heater 8\n#define stepPin A4\n#define dirPin A3\n\n//Temperature initialization\nint Temperature = 0;\nint SetTemperature = 300;\nint adc_val;\nbyte ShowTemp = 0;\nbyte HeaterCond=0;\n\n\n//Motor initialization\nbyte Speed = 2;\nbyte TestSpeed = 2;\nbyte TestSpeedCond=0;\nint MotorSpeed = 10;\nunsigned long previousMillisM = 0;\nbyte Motorcondi = 0;\nbyte MotorStart = 0;\n\n//Button initialization\nbyte ButtonNumber = 0;\nunsigned long previousMillisBtn = 0;\nbyte intervalBtn = 200;\nbyte ActiveBtn = 1;\nbyte BtnCondi = 0;\n\n//Action initialization\nbyte Windwos = 0;\n\nconst int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;\nLiquidCrystal lcd(rs, en, d4, d5, d6, d7);\n\nvoid setup() {\n Serial.begin(9600);\n lcd.begin(16, 2);\n pinMode(thermocouple, INPUT);\n pinMode(PRIV, INPUT);\n pinMode(ENTER, INPUT);\n pinMode(Next, INPUT);\n pinMode(Limit, INPUT);\n pinMode(Heater, OUTPUT);\n lcd.setCursor(0, 0);\n lcd.print(\"Negs Electronics\");\n lcd.setCursor(0, 1);\n lcd.print(\"Tel:- 0951754711\");\n delay(3000);\n lcd.setCursor(0, 0);\n lcd.print(\" \");\n lcd.setCursor(0, 1);\n lcd.print(\" \");\n LcdDisplay(1);\n}\nvoid loop() {\n Button();\n Action();\n Temps();\n Motor();\n /*\n lcd.setCursor(0, 1);\n lcd.print(ButtonNumber);\n if(ButtonNumber==1){\n Temperature=Temperature+1;\n ButtonNumber=0;\n ActiveBtn=0;\n }\n lcd.setCursor(0, 0);\n lcd.print(Temperature);\n */\n}\nvoid Action() {\n if (Windwos == 1) {\n if (ButtonNumber == 2) {\n LcdDisplay(4);\n ButtonNumber = 0;\n } else if (ButtonNumber == 3) {\n LcdDisplay(2);\n ButtonNumber = 0;\n }\n } else if (Windwos == 4) {\n if (ButtonNumber == 2) {\n LcdDisplay(1);\n ButtonNumber = 0;\n }\n } else if (Windwos == 2) {\n if (ButtonNumber == 1) {\n LcdDisplay(1);\n ButtonNumber = 0;\n } else if (ButtonNumber == 2) {\n LcdDisplay(5);\n ButtonNumber = 0;\n } else if (ButtonNumber == 3) {\n LcdDisplay(3);\n ButtonNumber = 0;\n }\n } else if (Windwos == 5) {\n if (ButtonNumber == 2) {\n LcdDisplay(2);\n ButtonNumber = 0;\n }else if (ButtonNumber == 1) {\n TestSpeed=TestSpeed>0? TestSpeed-1:TestSpeed;\n ButtonNumber = 0;\n }else if (ButtonNumber == 3) {\n TestSpeed=TestSpeed<10? TestSpeed+1:TestSpeed;\n ButtonNumber = 0;\n }\n \n }\n else if (Windwos == 3) {\n if (ButtonNumber == 1) {\n LcdDisplay(2);\n ButtonNumber = 0;\n } else if (ButtonNumber == 2) {\n LcdDisplay(6);\n ButtonNumber = 0;\n }\n else if (ButtonNumber == 3) {\n LcdDisplay(7);\n ButtonNumber = 0;\n }\n\n\n }\n else if (Windwos == 6) {\n if (ButtonNumber == 2) {\n LcdDisplay(3);\n ButtonNumber = 0;\n } else if (ButtonNumber == 1) {\n Speed=Speed>0? Speed-1:Speed;\n ButtonNumber = 0;\n }else if (ButtonNumber == 3) {\n Speed=Speed<10? Speed+1:Speed;\n ButtonNumber = 0;\n }\n }\n else if (Windwos == 7) {\n if (ButtonNumber == 1) {\n LcdDisplay(3);\n ButtonNumber = 0;\n } else if (ButtonNumber == 2) {\n LcdDisplay(8);\n ButtonNumber = 0;\n }\n }\n else if (Windwos == 8) {\n if (ButtonNumber == 2) {\n LcdDisplay(7);\n ButtonNumber = 0;\n }else if (ButtonNumber == 1) {\n SetTemperature=SetTemperature>100? SetTemperature-1:SetTemperature;\n ButtonNumber = 0;\n }else if (ButtonNumber == 3) {\n SetTemperature=SetTemperature<500? SetTemperature+1:SetTemperature;\n ButtonNumber = 0;\n }\n }\n\n\n\n}\nvoid Button() {\n timeBtn();\n if (BtnCondi) {\n BtnCondi = !BtnCondi;\n ButtonNumber = digitalRead(Next) == 1 ? 3 : ButtonNumber;\n ButtonNumber = digitalRead(ENTER) == 1 ? 2 : ButtonNumber;\n ButtonNumber = digitalRead(PRIV) == 1 ? 1 : ButtonNumber;\n ButtonNumber = digitalRead(Limit) == 1 ? 4 : ButtonNumber;\n }\n\n\n}\nvoid LcdDisplay(byte Condi) {\n switch (Condi) {\n case 1:\n lcd.setCursor(0, 0);\n //lcd.print(\" \");\n lcd.print(\"=>Start \");\n lcd.setCursor(0, 1);\n lcd.print(\" Test Motor \");\n Windwos = 1;\n ShowTemp=0;\n HeaterCond=0;\n break;\n case 2:\n lcd.setCursor(0, 0);\n //lcd.print(\" \");\n lcd.print(\"=>Test Motor \");\n lcd.setCursor(0, 1);\n lcd.print(\" Speed Setting \");\n Windwos = 2;\n TestSpeedCond=0;\n MotorStart=0;\n break;\n case 3:\n lcd.setCursor(0, 0);\n //lcd.print(\" \");\n lcd.print(\"=>Speed Setting \");\n lcd.setCursor(0, 1);\n lcd.print(\" Themp Setting \");\n Windwos = 3;\n TestSpeedCond=0;\n MotorStart=0;\n\n break;\n case 4:\n lcd.setCursor(0, 0);\n //lcd.print(\" \");\n lcd.print(\"<=Stop \");\n lcd.setCursor(0, 1);\n lcd.print(\"Sped=\");\n lcd.setCursor(5, 1);\n lcd.print(Speed);\n lcd.setCursor(7, 1);\n lcd.print(\" Temp=\");\n lcd.setCursor(13, 1);\n lcd.print(Temperature);\n ShowTemp = 1;\n HeaterCond=1;\n Windwos = 4;\n break;\n case 5:\n lcd.setCursor(0, 1);\n lcd.print(\" \");\n lcd.setCursor(0, 0);\n //lcd.print(\" \");\n lcd.print(\"<=Test Motor \");\n lcd.setCursor(0, 1);\n lcd.print(\"Speed = \");\n lcd.setCursor(8, 1);\n lcd.print(TestSpeed);\n Windwos = 5;\n TestSpeedCond=1;\n MotorStart=1;\n\n break;\n case 6:\n lcd.setCursor(0, 1);\n lcd.print(\" \");\n lcd.setCursor(0, 0);\n //lcd.print(\" \");\n lcd.print(\"<=Speed Setting \");\n lcd.setCursor(0, 1);\n lcd.print(\"Speed = \");\n lcd.setCursor(8, 1);\n lcd.print(Speed);\n Windwos = 6;\n TestSpeedCond=2;\n MotorStart=1;\n\n break;\n case 7:\n lcd.setCursor(0, 0);\n //lcd.print(\" \");\n lcd.print(\"=>Themp Setting \");\n lcd.setCursor(0, 1);\n lcd.print(\" \");\n Windwos = 7;\n ShowTemp = 0;\n\n break;\n case 8:\n lcd.setCursor(0, 0);\n //lcd.print(\" \");\n lcd.print(\"<=Themp Setting \");\n lcd.setCursor(0, 1);\n lcd.print(\"Temperatur=\");\n lcd.setCursor(11, 1);\n lcd.print(SetTemperature);\n Windwos = 8;\n ShowTemp = 2;\n break;\n }\n\n}\nvoid timeBtn() {\n unsigned long currentMillisBtn = millis();\n if (currentMillisBtn - previousMillisBtn >= intervalBtn) {\n previousMillisBtn = currentMillisBtn;\n BtnCondi = BtnCondi == 0 ? 1 : 0;\n ActiveBtn = 1;\n }\n}\nvoid Temps() {\n adc_val = analogRead(thermocouple);\n Temperature = (((adc_val * 4.88) - 0.0027) / 10.0);\n if (ShowTemp == 1)\n {\n lcd.setCursor(13, 1);\n lcd.print(Temperature);\n }\n else if (ShowTemp == 2)\n {\n lcd.setCursor(11, 1);\n lcd.print(SetTemperature);\n }\n if(HeaterCond){\n if(SetTemperature>=Temperature){\n digitalWrite(Heater,true);\n MotorStart=0;\n }else{\n digitalWrite(Heater,LOW);\n MotorStart=1;\n }\n }else{\n digitalWrite(Heater,LOW);\n if(Windwos==1){\n MotorStart=0;\n } \n\n }\n\n}\nvoid Motor(){\nif(TestSpeedCond==1){\n lcd.setCursor(8, 1);\n lcd.print(TestSpeed);\n if(TestSpeed==9){\n lcd.setCursor(9, 1);\n lcd.print(\" \");\n } \n}\nelse if(TestSpeedCond==2){\n lcd.setCursor(8, 1);\n lcd.print(Speed);\n if(Speed==9){\n lcd.setCursor(9, 1);\n lcd.print(\" \");\n } \n}\nif (MotorStart) {\n timeMotor();\n digitalWrite(dirPin, HIGH);\n if (Motorcondi == 0) {\n digitalWrite(stepPin, HIGH);\n } else {\n digitalWrite(stepPin, LOW);\n }\n }\n}\nvoid timeMotor() {\n if (Windwos == 6 || Windwos == 4) {\n MotorSpeed = Speed;\n } else if (Windwos == 5) {\n MotorSpeed = TestSpeed;\n }\n unsigned long currentMillisM = micros();\n if (currentMillisM - previousMillisM >= MotorSpeed * 99) {\n previousMillisM = currentMillisM;\n Motorcondi = Motorcondi == 0 ? 1 : 0;\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"negs electronics\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 106.2, \"left\": -39, \"attrs\": {} },\n { \"type\": \"wokwi-lcd1602\", \"id\": \"lcd1\", \"top\": -82.97, \"left\": 25.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": 83,\n \"left\": 297.6,\n \"attrs\": { \"color\": \"green\", \"key\": \"1\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn2\",\n \"top\": 140.6,\n \"left\": 297.6,\n \"attrs\": { \"color\": \"blue\", \"key\": \"2\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn3\",\n \"top\": 198.2,\n \"left\": 297.6,\n \"attrs\": { \"color\": \"green\", \"key\": \"3\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 282.35,\n \"left\": 326.4,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 301.55,\n \"left\": 326.4,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 320.75,\n \"left\": 326.4,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r4\",\n \"top\": 254.4,\n \"left\": -106.15,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn4\",\n \"top\": 159.8,\n \"left\": -153.6,\n \"attrs\": { \"color\": \"green\", \"bounce\": \"1\", \"key\": \"4\" }\n },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": 246, \"left\": 253.4, \"attrs\": { \"color\": \"red\" } },\n { \"type\": \"wokwi-a4988\", \"id\": \"drv1\", \"top\": 523.2, \"left\": 292.8, \"attrs\": {} },\n {\n \"type\": \"wokwi-stepper-motor\",\n \"id\": \"stepper1\",\n \"top\": 349.21,\n \"left\": 374.83,\n \"attrs\": { \"size\": \"17\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r5\",\n \"top\": 311.15,\n \"left\": 230.4,\n \"attrs\": { \"value\": \"1000\" }\n },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot1\", \"top\": -30.1, \"left\": 345.4, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r6\",\n \"top\": 493.55,\n \"left\": 134.4,\n \"attrs\": { \"value\": \"1000\" }\n }\n ],\n \"connections\": [\n [ \"lcd1:RS\", \"uno:2\", \"green\", [ \"v38.4\", \"h101.8\" ] ],\n [ \"lcd1:E\", \"uno:3\", \"green\", [ \"v28.8\", \"h72.8\" ] ],\n [ \"lcd1:D4\", \"uno:4\", \"green\", [ \"v19.2\", \"h9.6\" ] ],\n [ \"lcd1:D5\", \"uno:5\", \"green\", [ \"v0\" ] ],\n [ \"lcd1:D6\", \"uno:6\", \"green\", [ \"v9.6\", \"h-28.6\", \"v9.6\" ] ],\n [ \"lcd1:D7\", \"uno:7\", \"green\", [ \"v19.2\", \"h0.3\" ] ],\n [ \"lcd1:RW\", \"uno:GND.1\", \"green\", [ \"v38.4\", \"h-19.3\" ] ],\n [ \"btn3:2.r\", \"btn2:2.r\", \"green\", [ \"h38.6\", \"v-57.4\" ] ],\n [ \"btn1:2.r\", \"btn2:2.r\", \"green\", [ \"h38.6\", \"v57.8\" ] ],\n [ \"uno:5V\", \"btn3:2.r\", \"red\", [ \"v47.9\", \"h253.4\" ] ],\n [ \"uno:GND.2\", \"r3:1\", \"black\", [ \"v0\" ] ],\n [ \"r3:1\", \"r2:1\", \"green\", [ \"v0\" ] ],\n [ \"r1:1\", \"r2:1\", \"green\", [ \"v0\" ] ],\n [ \"btn3:1.r\", \"r1:2\", \"green\", [ \"v0\", \"h48.2\", \"v76.8\" ] ],\n [ \"btn2:1.r\", \"r2:2\", \"green\", [ \"v0\", \"h67.4\", \"v153.6\" ] ],\n [ \"btn1:1.r\", \"r3:2\", \"green\", [ \"v0\", \"h96.2\", \"v220.8\" ] ],\n [ \"uno:13\", \"btn1:1.r\", \"magenta\", [ \"v-57.6\", \"h154\" ] ],\n [ \"uno:12\", \"btn2:1.r\", \"yellow\", [ \"v-48\", \"h182.9\", \"v57.6\", \"h96\" ] ],\n [ \"uno:11\", \"btn3:1.r\", \"purple\", [ \"v-28.8\", \"h163.8\", \"v96\", \"h105.6\" ] ],\n [ \"btn4:1.r\", \"uno:10\", \"green\", [ \"v0\" ] ],\n [ \"uno:GND.3\", \"r4:2\", \"black\", [ \"v0\" ] ],\n [ \"r4:1\", \"btn4:1.r\", \"green\", [ \"h28.8\", \"v-57.6\", \"h-38.4\" ] ],\n [ \"uno:5V\", \"btn4:2.r\", \"red\", [ \"v47.9\", \"h-207.4\", \"v-144\", \"h19.2\", \"v-19.2\" ] ],\n [ \"drv1:2B\", \"stepper1:A-\", \"green\", [ \"h0\" ] ],\n [ \"drv1:2A\", \"stepper1:A+\", \"green\", [ \"h0\" ] ],\n [ \"stepper1:B+\", \"drv1:1A\", \"green\", [ \"v0\" ] ],\n [ \"drv1:1B\", \"stepper1:B-\", \"green\", [ \"h0\" ] ],\n [ \"drv1:RESET\", \"drv1:SLEEP\", \"green\", [ \"h-28.8\", \"v9.6\" ] ],\n [ \"drv1:STEP\", \"uno:A4\", \"green\", [ \"h-19.2\", \"v-240\", \"h-76.8\" ] ],\n [ \"drv1:DIR\", \"uno:A3\", \"green\", [ \"h-57.6\", \"v-259.2\", \"h-57.6\" ] ],\n [ \"drv1:VDD\", \"uno:5V\", \"green\", [ \"h-38.25\", \"v-211.12\", \"h-211.2\" ] ],\n [ \"uno:8\", \"led1:A\", \"green\", [ \"v-19.2\", \"h125.2\", \"v201.6\", \"h28.8\" ] ],\n [ \"r5:2\", \"led1:C\", \"green\", [ \"v-9.6\", \"h-30\" ] ],\n [ \"r5:1\", \"uno:GND.3\", \"green\", [ \"v0\", \"h-86.4\", \"v-19.2\" ] ],\n [ \"pot1:GND\", \"uno:GND.2\", \"black\", [ \"v0\" ] ],\n [ \"pot1:VCC\", \"uno:5V\", \"red\", [ \"v0\" ] ],\n [ \"pot1:SIG\", \"uno:A2\", \"green\", [ \"v38.4\", \"h86\" ] ],\n [ \"r6:1\", \"pot1:SIG\", \"green\", [ \"v0\", \"h-19.2\" ] ],\n [ \"r6:2\", \"pot1:GND\", \"green\", [ \"v-28.8\", \"h-97.2\", \"v-9.6\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for inbuilt LED blink", + "input": "int led = 13;\n\nvoid setup() {\n pinMode(led,OUTPUT);\n}\n\nvoid loop() {\n digitalWrite(led,HIGH);\n delay(500);\n digitalWrite(led,LOW);\n delay(500);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"8.9 Fikri nur Fauzi Siswanto\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0.6, \"left\": -0.6, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -42, \"left\": 99.8, \"attrs\": { \"color\": \"red\" } }\n ],\n \"connections\": [ [ \"led1:C\", \"uno:GND.1\", \"green\", [ \"v0\" ] ], [ \"led1:A\", \"uno:13\", \"green\", [ \"v0\" ] ] ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for wifi scanning using ESP32", + "input": "/* ESP32 WiFi Scanning example */\n\n#include \"WiFi.h\"\n\nvoid setup() {\n Serial.begin(115200);\n Serial.println(\"Initializing WiFi...\");\n WiFi.mode(WIFI_STA);\n Serial.println(\"Setup done!\");\n}\n\nvoid loop() {\n Serial.println(\"Scanning...\");\n\n // WiFi.scanNetworks will return the number of networks found\n int n = WiFi.scanNetworks();\n Serial.println(\"Scan done!\");\n if (n == 0) {\n Serial.println(\"No networks found.\");\n } else {\n Serial.println();\n Serial.print(n);\n Serial.println(\" networks found\");\n for (int i = 0; i < n; ++i) {\n // Print SSID and RSSI for each network found\n Serial.print(i + 1);\n Serial.print(\": \");\n Serial.print(WiFi.SSID(i));\n Serial.print(\" (\");\n Serial.print(WiFi.RSSI(i));\n Serial.print(\")\");\n Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? \" \" : \"*\");\n delay(10);\n }\n }\n Serial.println(\"\");\n\n // Wait a bit before scanning again\n delay(5000);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [ { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 0, \"left\": 0, \"attrs\": {} } ],\n \"connections\": [ [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ], [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ] ]\n}" + }, + { + "instruction": "Generate a diagram.json code for NTP clock", + "input": "// Learn about the ESP32 WiFi simulation in\n// https://docs.wokwi.com/guides/esp32-wifi\n\n#include \n#include \n#include \n\nLiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);\n\n#define NTP_SERVER \"pool.ntp.org\"\n#define UTC_OFFSET 0\n#define UTC_OFFSET_DST 0\n\nvoid spinner() {\n static int8_t counter = 0;\n const char* glyphs = \"\\xa1\\xa5\\xdb\";\n LCD.setCursor(15, 1);\n LCD.print(glyphs[counter++]);\n if (counter == strlen(glyphs)) {\n counter = 0;\n }\n}\n\nvoid printLocalTime() {\n struct tm timeinfo;\n if (!getLocalTime(&timeinfo)) {\n LCD.setCursor(0, 1);\n LCD.println(\"Connection Err\");\n return;\n }\n\n LCD.setCursor(8, 0);\n LCD.println(&timeinfo, \"%H:%M:%S\");\n\n LCD.setCursor(0, 1);\n LCD.println(&timeinfo, \"%d/%m/%Y %Z\");\n}\n\nvoid setup() {\n Serial.begin(115200);\n\n LCD.init();\n LCD.backlight();\n LCD.setCursor(0, 0);\n LCD.print(\"Connecting to \");\n LCD.setCursor(0, 1);\n LCD.print(\"WiFi \");\n\n WiFi.begin(\"Wokwi-GUEST\", \"\", 6);\n while (WiFi.status() != WL_CONNECTED) {\n delay(250);\n spinner();\n }\n\n Serial.println(\"\");\n Serial.println(\"WiFi connected\");\n Serial.print(\"IP address: \");\n Serial.println(WiFi.localIP());\n\n LCD.clear();\n LCD.setCursor(0, 0);\n LCD.println(\"Online\");\n LCD.setCursor(0, 1);\n LCD.println(\"Updating time...\");\n\n configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);\n}\n\nvoid loop() {\n printLocalTime();\n delay(250);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": -76.8, \"left\": 43.24, \"attrs\": {} },\n {\n \"type\": \"wokwi-lcd1602\",\n \"id\": \"lcd1\",\n \"top\": -70.4,\n \"left\": 188,\n \"attrs\": { \"pins\": \"i2c\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"lcd1:SDA\", \"esp:21\", \"green\", [ \"v-4.49\", \"h-28.8\", \"v23.89\" ] ],\n [ \"lcd1:GND\", \"esp:GND.2\", \"black\", [ \"h-16.67\", \"v162.78\" ] ],\n [ \"lcd1:VCC\", \"esp:3V3\", \"red\", [ \"h-9.6\", \"v-57.5\", \"h-134.55\" ] ],\n [ \"lcd1:SCL\", \"esp:22\", \"purple\", [ \"h-19.2\", \"v-18.9\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32 HTTP server", + "input": "/* ESP32 HTTP IoT Server Example for Wokwi.com\n\n https://wokwi.com/projects/320964045035274834\n\n To test, you need the Wokwi IoT Gateway, as explained here:\n\n https://docs.wokwi.com/guides/esp32-wifi#the-private-gateway\n\n Then start the simulation, and open http://localhost:9080\n in another browser tab.\n\n Note that the IoT Gateway requires a Wokwi Club subscription.\n To purchase a Wokwi Club subscription, go to https://wokwi.com/club\n*/\n\n#include \n#include \n#include \n#include \n\n#define WIFI_SSID \"Wokwi-GUEST\"\n#define WIFI_PASSWORD \"\"\n// Defining the WiFi channel speeds up the connection:\n#define WIFI_CHANNEL 6\n\nWebServer server(80);\n\nconst int LED1 = 26;\nconst int LED2 = 27;\n\nbool led1State = false;\nbool led2State = false;\n\nvoid sendHtml() {\n String response = R\"(\n \n \n ESP32 Web Server Demo\n \n \n \n \n \n

ESP32 Web Server

\n\n
\n

LED 1

\n LED1_TEXT\n

LED 2

\n LED2_TEXT\n
\n \n \n )\";\n response.replace(\"LED1_TEXT\", led1State ? \"ON\" : \"OFF\");\n response.replace(\"LED2_TEXT\", led2State ? \"ON\" : \"OFF\");\n server.send(200, \"text/html\", response);\n}\n\nvoid setup(void) {\n Serial.begin(115200);\n pinMode(LED1, OUTPUT);\n pinMode(LED2, OUTPUT);\n\n WiFi.begin(WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL);\n Serial.print(\"Connecting to WiFi \");\n Serial.print(WIFI_SSID);\n // Wait for connection\n while (WiFi.status() != WL_CONNECTED) {\n delay(100);\n Serial.print(\".\");\n }\n Serial.println(\" Connected!\");\n\n Serial.print(\"IP address: \");\n Serial.println(WiFi.localIP());\n\n server.on(\"/\", sendHtml);\n\n server.on(UriBraces(\"/toggle/{}\"), []() {\n String led = server.pathArg(0);\n Serial.print(\"Toggle LED #\");\n Serial.println(led);\n\n switch (led.toInt()) {\n case 1:\n led1State = !led1State;\n digitalWrite(LED1, led1State);\n break;\n case 2:\n led2State = !led2State;\n digitalWrite(LED2, led2State);\n break;\n }\n\n sendHtml();\n });\n\n server.begin();\n Serial.println(\"HTTP server started\");\n}\n\nvoid loop(void) {\n server.handleClient();\n delay(2);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 0, \"left\": -4.76, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 109.55,\n \"left\": -76.8,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 119.15,\n \"left\": -76.8,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": 34.8,\n \"left\": -111.4,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": 63.6,\n \"left\": -140.2,\n \"attrs\": { \"color\": \"green\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"r1:1\", \"led1:A\", \"green\", [ \"v0.07\", \"h-10\" ] ],\n [ \"r2:1\", \"led2:A\", \"green\", [ \"h-38.4\", \"v-19.2\" ] ],\n [ \"esp:GND.1\", \"led2:C\", \"black\", [ \"h0\" ] ],\n [ \"esp:GND.1\", \"led1:C\", \"black\", [ \"h0\" ] ],\n [ \"esp:26\", \"r1:2\", \"green\", [ \"h0\" ] ],\n [ \"r2:2\", \"esp:27\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32 joke machine", + "input": "/*\n ESP32 HTTPClient Jokes API Example\n\n https://wokwi.com/projects/342032431249883731\n\n Copyright (C) 2022, Uri Shaked\n*/\n\n#include \n#include \n#include \n#include \n#include \n\nconst char* ssid = \"Wokwi-GUEST\";\nconst char* password = \"\";\n\n#define BTN_PIN 5\n#define TFT_DC 2\n#define TFT_CS 15\nAdafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);\n\nconst String url = \"https://v2.jokeapi.dev/joke/Programming\";\n\nString getJoke() {\n HTTPClient http;\n http.useHTTP10(true);\n http.begin(url);\n http.GET();\n String result = http.getString();\n\n DynamicJsonDocument doc(2048);\n DeserializationError error = deserializeJson(doc, result);\n\n // Test if parsing succeeds.\n if (error) {\n Serial.print(\"deserializeJson() failed: \");\n Serial.println(error.c_str());\n return \"\";\n }\n\n String type = doc[\"type\"].as();\n String joke = doc[\"joke\"].as();\n String setup = doc[\"setup\"].as();\n String delivery = doc[\"delivery\"].as();\n http.end();\n return type.equals(\"single\") ? joke : setup + \" \" + delivery;\n}\n\nvoid nextJoke() {\n tft.setTextColor(ILI9341_WHITE);\n tft.println(\"\\nLoading joke...\");\n\n String joke = getJoke();\n tft.setTextColor(ILI9341_GREEN);\n tft.println(joke);\n}\n\nvoid setup() {\n pinMode(BTN_PIN, INPUT_PULLUP);\n\n WiFi.begin(ssid, password, 6);\n\n tft.begin();\n tft.setRotation(1);\n\n tft.setTextColor(ILI9341_WHITE);\n tft.setTextSize(2);\n tft.print(\"Connecting to WiFi\");\n\n while (WiFi.status() != WL_CONNECTED) {\n delay(100);\n tft.print(\".\");\n }\n\n tft.print(\"\\nOK! IP=\");\n tft.println(WiFi.localIP());\n\n nextJoke();\n}\n\nvoid loop() {\n if (digitalRead(BTN_PIN) == LOW) {\n tft.fillScreen(ILI9341_BLACK);\n tft.setCursor(0, 0);\n nextJoke();\n }\n\n delay(100);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"board-esp32-devkit-c-v4\",\n \"id\": \"esp\",\n \"top\": 96,\n \"left\": -158.36,\n \"attrs\": { \"fastTLS\": \"1\" }\n },\n {\n \"type\": \"wokwi-ili9341\",\n \"id\": \"lcd1\",\n \"top\": 34.2,\n \"left\": 88.1,\n \"rotate\": 90,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": 294.2,\n \"left\": 144,\n \"attrs\": { \"color\": \"green\", \"label\": \"New joke\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"lcd1:GND\", \"esp:GND.2\", \"black\", [ \"h-19.2\", \"v91.54\" ] ],\n [ \"lcd1:RST\", \"esp:4\", \"purple\", [ \"h-48\", \"v67.2\" ] ],\n [ \"lcd1:D/C\", \"esp:2\", \"#8f4814\", [ \"h-28.8\", \"v44.14\" ] ],\n [ \"lcd1:SCK\", \"esp:18\", \"gray\", [ \"v-0.01\", \"h-48\", \"v-19.2\" ] ],\n [ \"lcd1:MISO\", \"esp:19\", \"orange\", [ \"h-67.2\", \"v-9.61\", \"h0\", \"v-19.2\" ] ],\n [ \"lcd1:MOSI\", \"esp:23\", \"green\", [ \"h-38.4\", \"v-67.31\" ] ],\n [ \"esp:5V\", \"lcd1:VCC\", \"red\", [ \"h-21.83\", \"v-206.3\", \"h201.6\", \"v48.5\" ] ],\n [ \"lcd1:CS\", \"esp:15\", \"violet\", [ \"h-57.6\", \"v105.6\" ] ],\n [ \"esp:GND.2\", \"btn1:2.l\", \"black\", [ \"h76.8\", \"v201.4\" ] ],\n [ \"esp:5\", \"btn1:1.l\", \"green\", [ \"h19.2\", \"v96\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for oled display with esp32 using micropython", + "input": "from machine import Pin, I2C\nimport ssd1306\n\n# ESP32 Pin assignment \ni2c = I2C(0, scl=Pin(22), sda=Pin(21))\n\noled_width = 128\noled_height = 64\noled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)\n\noled.text('Hello, Wokwi!', 10, 10) \noled.show()", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"board-esp32-devkit-c-v4\",\n \"id\": \"esp\",\n \"top\": 9.6,\n \"left\": -100.76,\n \"attrs\": { \"env\": \"micropython-20231005-v1.21.0\" }\n },\n { \"type\": \"board-ssd1306\", \"id\": \"oled1\", \"top\": 99.14, \"left\": 57.83, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"oled1:SCL\", \"esp:22\", \"green\", [ \"v0\" ] ],\n [ \"oled1:SDA\", \"esp:21\", \"blue\", [ \"v-19.2\", \"h-124.73\" ] ],\n [ \"oled1:GND\", \"esp:GND.2\", \"black\", [ \"v-67.2\", \"h-96\" ] ],\n [ \"oled1:VCC\", \"esp:3V3\", \"red\", [ \"v-28.8\", \"h0.15\", \"v-76.8\", \"h-201.75\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for micro-python MQTT weather logger with ESP32", + "input": "import network\nimport time\nfrom machine import Pin\nimport dht\nimport ujson\nfrom umqtt.simple import MQTTClient\n\n# MQTT Server Parameters\nMQTT_CLIENT_ID = \"micropython-weather-demo\"\nMQTT_BROKER = \"broker.mqttdashboard.com\"\nMQTT_USER = \"\"\nMQTT_PASSWORD = \"\"\nMQTT_TOPIC = \"wokwi-weather\"\n\nsensor = dht.DHT22(Pin(15))\n\nprint(\"Connecting to WiFi\", end=\"\")\nsta_if = network.WLAN(network.STA_IF)\nsta_if.active(True)\nsta_if.connect('Wokwi-GUEST', '')\nwhile not sta_if.isconnected():\n print(\".\", end=\"\")\n time.sleep(0.1)\nprint(\" Connected!\")\n\nprint(\"Connecting to MQTT server... \", end=\"\")\nclient = MQTTClient(MQTT_CLIENT_ID, MQTT_BROKER, user=MQTT_USER, password=MQTT_PASSWORD)\nclient.connect()\n\nprint(\"Connected!\")\n\nprev_weather = \"\"\nwhile True:\n print(\"Measuring weather conditions... \", end=\"\")\n sensor.measure() \n message = ujson.dumps({\n \"temp\": sensor.temperature(),\n \"humidity\": sensor.humidity(),\n })\n if message != prev_weather:\n print(\"Updated!\")\n print(\"Reporting to MQTT topic {}: {}\".format(MQTT_TOPIC, message))\n client.publish(MQTT_TOPIC, message)\n prev_weather = message\n else:\n print(\"No change\")\n time.sleep(1)", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": -37.58, \"left\": -96.37, \"attrs\": {} },\n { \"type\": \"wokwi-dht22\", \"id\": \"dht1\", \"top\": -32.2, \"left\": 40.16, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"dht1:VCC\", \"esp:3V3\", \"red\", [ \"v109.3\", \"h-170.36\", \"v-200.78\" ] ],\n [ \"dht1:SDA\", \"esp:15\", \"green\", [ \"v0\" ] ],\n [ \"dht1:GND\", \"esp:GND.1\", \"black\", [ \"v99.7\", \"h-189.56\", \"v-66.38\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for simon says esp32-c3", + "input": "#include \"pitches.h\"\n\n/* Define pin numbers for LEDs, buttons and speaker: */\nconst uint8_t buttonPins[] = {0, 1, 2, 3};\nconst uint8_t ledPins[] = {8, 7, 6, 5};\n#define SPEAKER_PIN 10\n\n// These are connected to 74HC595 shift register (used to show game score):\nconst int LATCH_PIN = 18; // 74HC595 pin 12\nconst int DATA_PIN = 19; // 74HC595 pin 14\nconst int CLOCK_PIN = 9; // 74HC595 pin 11\n\n#define MAX_GAME_LENGTH 100\n\nconst int gameTones[] = { NOTE_G3, NOTE_C4, NOTE_E4, NOTE_G5};\n\n/* Global variables - store the game state */\nuint8_t gameSequence[MAX_GAME_LENGTH] = {0};\nuint8_t gameIndex = 0;\n\n/**\n Set up the Arduino board and initialize Serial communication\n*/\nvoid setup() {\n Serial.begin(9600);\n for (byte i = 0; i < 4; i++) {\n pinMode(ledPins[i], OUTPUT);\n pinMode(buttonPins[i], INPUT_PULLUP);\n }\n pinMode(SPEAKER_PIN, OUTPUT);\n pinMode(LATCH_PIN, OUTPUT);\n pinMode(CLOCK_PIN, OUTPUT);\n pinMode(DATA_PIN, OUTPUT);\n\n // The following line primes the random number generator.\n // It assumes pin 4 is floating (disconnected):\n randomSeed(analogRead(4));\n}\n\n/* Digit table for the 7-segment display */\nconst uint8_t digitTable[] = {\n 0b11000000,\n 0b11111001,\n 0b10100100,\n 0b10110000,\n 0b10011001,\n 0b10010010,\n 0b10000010,\n 0b11111000,\n 0b10000000,\n 0b10010000,\n};\nconst uint8_t DASH = 0b10111111;\n\nvoid sendScore(uint8_t high, uint8_t low) {\n digitalWrite(LATCH_PIN, LOW);\n shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, low);\n shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, high);\n digitalWrite(LATCH_PIN, HIGH);\n}\n\nvoid displayScore() {\n int high = gameIndex % 100 / 10;\n int low = gameIndex % 10;\n sendScore(high ? digitTable[high] : 0xff, digitTable[low]);\n}\n\n/**\n Lights the given LED and plays a suitable tone\n*/\nvoid lightLedAndPlayTone(byte ledIndex) {\n digitalWrite(ledPins[ledIndex], HIGH);\n tone(SPEAKER_PIN, gameTones[ledIndex]);\n delay(300);\n digitalWrite(ledPins[ledIndex], LOW);\n noTone(SPEAKER_PIN);\n}\n\n/**\n Plays the current sequence of notes that the user has to repeat\n*/\nvoid playSequence() {\n for (int i = 0; i < gameIndex; i++) {\n byte currentLed = gameSequence[i];\n lightLedAndPlayTone(currentLed);\n delay(50);\n }\n}\n\n/**\n Waits until the user pressed one of the buttons,\n and returns the index of that button\n*/\nbyte readButtons() {\n while (true) {\n for (byte i = 0; i < 4; i++) {\n byte buttonPin = buttonPins[i];\n if (digitalRead(buttonPin) == LOW) {\n return i;\n }\n }\n delay(1);\n }\n}\n\n/**\n Play the game over sequence, and report the game score\n*/\nvoid gameOver() {\n Serial.print(\"Game over! your score: \");\n Serial.println(gameIndex - 1);\n gameIndex = 0;\n delay(200);\n\n // Play a Wah-Wah-Wah-Wah sound\n tone(SPEAKER_PIN, NOTE_DS5);\n delay(300);\n tone(SPEAKER_PIN, NOTE_D5);\n delay(300);\n tone(SPEAKER_PIN, NOTE_CS5);\n delay(300);\n for (byte i = 0; i < 10; i++) {\n for (int pitch = -10; pitch <= 10; pitch++) {\n tone(SPEAKER_PIN, NOTE_C5 + pitch);\n delay(6);\n }\n }\n noTone(SPEAKER_PIN);\n\n sendScore(DASH, DASH);\n delay(500);\n}\n\n/**\n Get the user's input and compare it with the expected sequence.\n*/\nbool checkUserSequence() {\n for (int i = 0; i < gameIndex; i++) {\n byte expectedButton = gameSequence[i];\n byte actualButton = readButtons();\n lightLedAndPlayTone(actualButton);\n if (expectedButton != actualButton) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n Plays a hooray sound whenever the user finishes a level\n*/\nvoid playLevelUpSound() {\n tone(SPEAKER_PIN, NOTE_E4);\n delay(150);\n tone(SPEAKER_PIN, NOTE_G4);\n delay(150);\n tone(SPEAKER_PIN, NOTE_E5);\n delay(150);\n tone(SPEAKER_PIN, NOTE_C5);\n delay(150);\n tone(SPEAKER_PIN, NOTE_D5);\n delay(150);\n tone(SPEAKER_PIN, NOTE_G5);\n delay(150);\n noTone(SPEAKER_PIN);\n}\n\n/**\n The main game loop\n*/\nvoid loop() {\n displayScore();\n\n // Add a random color to the end of the sequence\n gameSequence[gameIndex] = random(0, 4);\n gameIndex++;\n if (gameIndex >= MAX_GAME_LENGTH) {\n gameIndex = MAX_GAME_LENGTH - 1;\n }\n\n playSequence();\n if (!checkUserSequence()) {\n gameOver();\n }\n\n delay(300);\n\n if (gameIndex > 0) {\n playLevelUpSound();\n delay(300);\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"buzzer\",\n \"top\": 21.6,\n \"left\": 126.6,\n \"attrs\": { \"volume\": \"0.1\" }\n },\n { \"type\": \"wokwi-led\", \"id\": \"led-red\", \"top\": 6, \"left\": 3.8, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led-green\",\n \"top\": 73.2,\n \"left\": 3.8,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led-blue\",\n \"top\": 6,\n \"left\": 272.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led-yellow\",\n \"top\": 73.2,\n \"left\": 272.6,\n \"attrs\": { \"color\": \"yellow\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn-red\",\n \"top\": 6.2,\n \"left\": 48,\n \"attrs\": { \"color\": \"red\", \"key\": \"1\", \"label\": \"1\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn-green\",\n \"top\": 73.4,\n \"left\": 48,\n \"attrs\": { \"color\": \"green\", \"key\": \"2\", \"label\": \"2\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn-blue\",\n \"top\": 6.2,\n \"left\": 201.6,\n \"attrs\": { \"color\": \"blue\", \"key\": \"3\", \"label\": \"3\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn-yellow\",\n \"top\": 73.4,\n \"left\": 201.6,\n \"attrs\": { \"color\": \"yellow\", \"key\": \"4\", \"label\": \"4\" }\n },\n {\n \"type\": \"wokwi-74hc595\",\n \"id\": \"sr1\",\n \"top\": 171.8,\n \"left\": 361.16,\n \"rotate\": 180,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-74hc595\",\n \"id\": \"sr2\",\n \"top\": 171.8,\n \"left\": 457.16,\n \"rotate\": 180,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-7segment\", \"id\": \"sevseg1\", \"top\": 47.16, \"left\": 379.48, \"attrs\": {} },\n { \"type\": \"wokwi-7segment\", \"id\": \"sevseg2\", \"top\": 47.16, \"left\": 446.68, \"attrs\": {} },\n {\n \"type\": \"board-esp32-c3-devkitm-1\",\n \"id\": \"esp\",\n \"top\": 136.02,\n \"left\": 120.9,\n \"rotate\": 90,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 196.8,\n \"left\": 9.05,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 235.2,\n \"left\": -0.55,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 235.2,\n \"left\": 268.25,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r4\",\n \"top\": 196.8,\n \"left\": 277.85,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"esp:GND.1\", \"buzzer:1\", \"black\", [ \"v-9.6\", \"h-19.2\", \"v-38.4\", \"h-57.6\" ] ],\n [ \"esp:0\", \"btn-yellow:1.l\", \"gold\", [ \"v-38.4\", \"h42\", \"v-48\" ] ],\n [ \"esp:GND.1\", \"btn-yellow:2.r\", \"black\", [ \"v-9.6\", \"h48\", \"v-57.8\" ] ],\n [ \"esp:1\", \"btn-blue:1.l\", \"blue\", [ \"v-43.2\", \"h47.6\", \"v-110.4\" ] ],\n [ \"esp:GND.1\", \"btn-blue:2.r\", \"black\", [ \"v-9.6\", \"h48\", \"v-125\" ] ],\n [ \"esp:3\", \"btn-green:2.r\", \"green\", [ \"v-19.2\", \"h-72\", \"v-48.2\" ] ],\n [ \"esp:GND.1\", \"btn-green:1.l\", \"black\", [ \"v-9.6\", \"h-188.4\", \"v-76.8\" ] ],\n [ \"esp:2\", \"btn-red:2.r\", \"orange\", [ \"v-24\", \"h-76.8\", \"v-110.6\" ] ],\n [ \"esp:GND.1\", \"btn-red:1.l\", \"black\", [ \"v-9.6\", \"h-188.4\", \"v-144\" ] ],\n [ \"esp:10\", \"buzzer:2\", \"purple\", [ \"v-57.6\", \"h29.2\" ] ],\n [ \"esp:GND.1\", \"led-yellow:C\", \"black\", [ \"v-9.6\", \"h48\", \"v-44\", \"h9.2\" ] ],\n [ \"esp:GND.1\", \"led-blue:C\", \"black\", [ \"v-9.6\", \"h48\", \"v-111.2\", \"h9.2\" ] ],\n [ \"esp:GND.1\", \"led-green:C\", \"black\", [ \"v-9.6\", \"h-220.8\", \"v-48\" ] ],\n [ \"esp:GND.1\", \"led-red:C\", \"black\", [ \"v-9.6\", \"h-220.8\", \"v-115.2\" ] ],\n [ \"esp:3V3.1\", \"sr1:VCC\", \"red\", [ \"v-19.2\", \"h96\", \"v67.2\", \"h115.2\" ] ],\n [ \"esp:9\", \"sr1:SHCP\", \"gray\", [ \"v21.58\", \"h192\" ] ],\n [ \"esp:18\", \"sr1:STCP\", \"purple\", [ \"v26.38\", \"h278.4\" ] ],\n [ \"esp:19\", \"sr1:DS\", \"blue\", [ \"v31.18\", \"h307.2\" ] ],\n [ \"sr1:SHCP\", \"sr2:SHCP\", \"gray\", [ \"v47\", \"h106.12\" ] ],\n [ \"sr1:STCP\", \"sr2:STCP\", \"purple\", [ \"v37.4\", \"h96.52\" ] ],\n [ \"sr1:Q7S\", \"sr2:DS\", \"blue\", [ \"h0.52\", \"v56.6\", \"h144\" ] ],\n [ \"sr1:VCC\", \"sr1:MR\", \"red\", [ \"v17\", \"h-57.6\" ] ],\n [ \"sr1:VCC\", \"sr2:MR\", \"red\", [ \"v17\", \"h38.4\" ] ],\n [ \"sr1:VCC\", \"sr2:VCC\", \"red\", [ \"v17\", \"h96\" ] ],\n [ \"sr1:OE\", \"sr2:OE\", \"black\", [ \"v26.6\", \"h96\" ] ],\n [ \"sr1:MR\", \"sevseg1:COM.1\", \"red\", [ \"v17\", \"h-57.6\", \"v-96\", \"h76.8\" ] ],\n [ \"sevseg1:COM.1\", \"sevseg2:COM.1\", \"red\", [ \"h0\", \"v9.6\", \"h57.6\" ] ],\n [ \"sr2:Q0\", \"sevseg2:A\", \"green\", [ \"v7.4\", \"h28.8\", \"v-182.4\", \"h-67.2\" ] ],\n [ \"sr2:Q1\", \"sevseg2:B\", \"green\", [ \"v0\", \"h9.6\", \"v-134.4\", \"h-48\" ] ],\n [ \"sr2:Q2\", \"sevseg2:C\", \"green\", [ \"v-38.4\", \"h-38.4\" ] ],\n [ \"sr2:Q3\", \"sevseg2:D\", \"green\", [ \"v-33.6\", \"h-33.6\", \"v-9.6\", \"h-14.4\" ] ],\n [ \"sr2:Q4\", \"sevseg2:E\", \"green\", [ \"v-28.8\", \"h-28.8\", \"v-9.6\", \"h-14.4\" ] ],\n [ \"sr2:Q5\", \"sevseg2:F\", \"green\", [ \"v-24\", \"h-24\", \"v-9.6\", \"h-24\", \"v-110.4\", \"h19.2\" ] ],\n [ \"sr2:Q6\", \"sevseg2:G\", \"green\", [ \"v-19.2\", \"h-43.2\", \"v-115.2\", \"h14.4\" ] ],\n [ \"sr1:GND\", \"sr2:GND\", \"black\", [ \"v-9.6\", \"h96\" ] ],\n [ \"sr1:Q1\", \"sevseg1:B\", \"green\", [ \"v-134.4\", \"h-19.2\" ] ],\n [ \"sr1:Q2\", \"sevseg1:C\", \"green\", [ \"v-38.4\", \"h-19.2\" ] ],\n [ \"sr1:Q3\", \"sevseg1:D\", \"green\", [ \"v-33.6\", \"h-24\" ] ],\n [ \"sr1:Q4\", \"sevseg1:E\", \"green\", [ \"v-28.8\", \"h-28.8\" ] ],\n [ \"esp:GND.1\", \"sr1:GND\", \"black\", [ \"v-9.6\", \"h134.4\" ] ],\n [ \"sr1:GND\", \"sr1:OE\", \"black\", [ \"v-9.6\", \"h-9.6\", \"v67.2\", \"h172.8\" ] ],\n [ \"sr1:Q0\", \"sevseg1:A\", \"green\", [ \"v65\", \"h-76.8\", \"v-240\", \"h57.6\" ] ],\n [ \"sr1:Q5\", \"sevseg1:F\", \"green\", [ \"v-24\", \"h-19.2\", \"v-110.4\", \"h19.2\" ] ],\n [ \"sr1:Q6\", \"sevseg1:G\", \"green\", [ \"v-19.2\", \"h-14.4\", \"v-110.4\", \"h14.4\" ] ],\n [ \"esp:6\", \"r1:2\", \"orange\", [ \"v7.18\", \"h-115.2\" ] ],\n [ \"r1:1\", \"led-red:A\", \"orange\", [ \"v-105.6\", \"h-9.6\" ] ],\n [ \"esp:5\", \"r2:2\", \"green\", [ \"v11.98\", \"h-115.2\" ] ],\n [ \"r2:1\", \"led-green:A\", \"green\", [ \"h0\" ] ],\n [ \"r3:2\", \"esp:8\", \"gold\", [ \"v3.6\", \"h-115.2\" ] ],\n [ \"r3:1\", \"led-yellow:A\", \"gold\", [ \"h0\" ] ],\n [ \"r4:2\", \"esp:7\", \"blue\", [ \"v46.8\", \"h-144\" ] ],\n [ \"r4:1\", \"led-blue:A\", \"blue\", [ \"v-105.6\", \"h-9.6\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for esp32-c3 alarm clock", + "input": "#include \n#include \"Clock.h\"\n#include \"Weather.h\"\n#include \n#include \n#include \n#include \n\n#define I2C_ADDR 0x27\n#define LCD_COLUMNS 16\n#define LCD_LINES 2\n\nuint8_t state;\nunsigned long clockTimer;\nunsigned long weatherAPItimer;\nunsigned long weatherDisplayTimer;\n\nconst char* password = \"\";\nconst char* ssid = \"Wokwi-GUEST\";\n\nuint8_t valIndex;\nuint8_t cursorPos;\nchar entered_value [6];\nconst uint8_t ROWS = 4;\nconst uint8_t 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};\nuint8_t colPins[COLS] = { 1, 0, 3, 2 };\nuint8_t rowPins[ROWS] = { 4, 5, 6, 7 };\n\nLiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);\nClock rtc(&lcd);\nKeypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);\n\nvoid enterTime()\n{\n state = 1;\n memset(&entered_value[0], 0, sizeof(entered_value));\n cursorPos = 0;\n valIndex = 0;\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.print(\"Set clock then \");\n lcd.setCursor(0, 1);\n lcd.print(\"press # to save.\");\n delay(3000);\n lcd.clear();\n}\n\nvoid enterAlarm()\n{\n state = 2;\n memset(&entered_value[0], 0, sizeof(entered_value));\n cursorPos = 0;\n valIndex = 0;\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.print(\"Enter alarm time\");\n lcd.setCursor(0, 1);\n lcd.print(\"press # to save.\");\n delay(3000);\n lcd.clear();\n}\n\nvoid nextChar(char key)\n{\n if (valIndex < 6)\n {\n entered_value[valIndex] = key;\n lcd.setCursor(0, 0);\n lcd.print(entered_value);\n cursorPos++;\n valIndex++;\n }\n}\n\nvoid eraseChar()\n{\n if (valIndex > 0 )\n {\n valIndex--;\n cursorPos--;\n entered_value[valIndex] = '\\0';\n lcd.setCursor(cursorPos, 0);\n lcd.print(' ');\n lcd.setCursor(cursorPos, 0);\n }\n}\n\nvoid keyPadState0()\n{\n char key = keypad.getKey();\n switch(key)\n {\n case 'A':\n enterAlarm();\n break;\n case 'C':\n enterTime();\n break;\n case '#':\n rtc.silence();\n break;\n case '*':\n rtc.addToSnooze();\n break;\n }\n}\n\nvoid keyPadState1()\n{\n char key = keypad.getKey();\n switch(key)\n {\n case '#':\n rtc.setTime(entered_value);\n state = 0;\n break;\n case '*':\n eraseChar();\n break;\n default:\n if (isDigit(key))\n {\n nextChar(key);\n }\n break;\n }\n}\n\nvoid keyPadState2()\n{\n char key = keypad.getKey();\n switch(key)\n {\n case '#':\n rtc.setAlarm(entered_value);\n state = 0;\n break;\n case '*':\n eraseChar();\n break;\n default:\n if (isDigit(key))\n {\n nextChar(key);\n }\n break;\n }\n}\n\nvoid getInput()\n{\n switch (state)\n {\n case 0:\n keyPadState0();\n break;\n case 1:\n keyPadState1();\n break;\n case 2:\n keyPadState2();\n break;\n }\n}\n\nvoid setup() \n{\n pinMode(8, OUTPUT);\n pinMode(10, OUTPUT);\n Wire.begin(18, 19);\n lcd.init();\n lcd.backlight();\n WiFi.begin(ssid, password);\n while (WiFi.status() != WL_CONNECTED) \n {\n lcd.print(\".\");\n delay(1000);\n }\n lcd.clear();\n if (!rtc.setTimeFromAPI())\n {\n char t [] = __TIME__;\n char compileTime [] = { t[0], t[1], t[3], t[4], t[6], t[7] };\n rtc.setTime(compileTime);\n }\n getWeather(lcd);\n printWeather(lcd);\n}\n\nvoid loop() \n{\n if (state == 0)\n {\n unsigned long millisNow = millis();\n if (millisNow - clockTimer >= 1000)\n {\n clockTimer = millisNow;\n rtc.updateClock();\n }\n if (millisNow - weatherDisplayTimer >= 10000)\n {\n weatherDisplayTimer = millisNow;\n printWeather(lcd);\n }\n if (millisNow - weatherAPItimer >= 3600000)\n {\n weatherAPItimer = millisNow;\n getWeather(lcd);\n }\n }\n getInput(); \n}", + "output": "{\n \"version\": 1,\n \"author\": \"Maverick\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"board-esp32-c3-devkitm-1\",\n \"id\": \"esp\",\n \"top\": -454.69,\n \"left\": 262.1,\n \"rotate\": 90,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-membrane-keypad\",\n \"id\": \"keypad1\",\n \"top\": -824.35,\n \"left\": 162.4,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-lcd1602\",\n \"id\": \"lcd1\",\n \"top\": -444.26,\n \"left\": 414.36,\n \"attrs\": { \"pins\": \"i2c\" }\n },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -479.95,\n \"left\": 71.13,\n \"rotate\": 270,\n \"attrs\": { \"volume\": \"0.1\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": -380.49,\n \"left\": 88.44,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": -250.19,\n \"left\": 181.17,\n \"rotate\": 180,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-text\",\n \"id\": \"A\",\n \"top\": -772.62,\n \"left\": 404.66,\n \"attrs\": { \"text\": \"<------- Set Alarm\" }\n },\n {\n \"type\": \"wokwi-text\",\n \"id\": \"C\",\n \"top\": -666.01,\n \"left\": 405.29,\n \"attrs\": { \"text\": \"<------- Set Clock\" }\n },\n { \"type\": \"wokwi-text\", \"id\": \"|1\", \"top\": -578.59, \"left\": 322.96, \"attrs\": { \"text\": \"|\" } },\n { \"type\": \"wokwi-text\", \"id\": \"^1\", \"top\": -581.3, \"left\": 321.71, \"attrs\": { \"text\": \"^\" } },\n {\n \"type\": \"wokwi-text\",\n \"id\": \"#\",\n \"top\": -572.97,\n \"left\": 326.2,\n \"attrs\": { \"text\": \"------------------------------ Submit / Silence Alarm\" }\n },\n {\n \"type\": \"wokwi-text\",\n \"id\": \"*\",\n \"top\": -572.62,\n \"left\": 22.16,\n \"attrs\": { \"text\": \"Erase / Snooze-----------------\" }\n },\n { \"type\": \"wokwi-text\", \"id\": \"^2\", \"top\": -580.39, \"left\": 206.9, \"attrs\": { \"text\": \"^\" } },\n { \"type\": \"wokwi-text\", \"id\": \"|2\", \"top\": -579.17, \"left\": 208.11, \"attrs\": { \"text\": \"|\" } }\n ],\n \"connections\": [\n [ \"esp:1\", \"keypad1:C1\", \"cyan\", [ \"v-18.48\", \"h15.7\" ] ],\n [ \"esp:0\", \"keypad1:C2\", \"yellow\", [ \"v-9.6\", \"h10.51\" ] ],\n [ \"esp:3\", \"keypad1:C3\", \"limegreen\", [ \"v-9.59\", \"h-13.05\" ] ],\n [ \"esp:2\", \"keypad1:C4\", \"magenta\", [ \"v-18.48\", \"h-12.9\" ] ],\n [ \"esp:4\", \"keypad1:R1\", \"#8f4814\", [ \"v7.96\", \"h-84.23\", \"v-144.63\", \"h71.03\" ] ],\n [ \"esp:5\", \"keypad1:R2\", \"orange\", [ \"v14.55\", \"h-87.01\", \"v-144.5\", \"h74.21\" ] ],\n [ \"esp:6\", \"keypad1:R3\", \"green\", [ \"v20.84\", \"h-89.17\", \"v-143.71\", \"h76.27\" ] ],\n [ \"esp:7\", \"keypad1:R4\", \"purple\", [ \"v27.13\", \"h-91.33\", \"v-143.27\", \"h78.33\" ] ],\n [ \"lcd1:GND\", \"esp:GND.1\", \"black\", [ \"h-11.48\", \"v-27.23\", \"h-35.28\" ] ],\n [ \"lcd1:VCC\", \"esp:3V3.1\", \"red\", [ \"h-18.59\", \"v-30.7\", \"h-37.77\" ] ],\n [ \"lcd1:SCL\", \"esp:19\", \"limegreen\", [ \"h-10.71\", \"v117.57\", \"h-160.66\", \"v-62.9\" ] ],\n [ \"lcd1:SDA\", \"esp:18\", \"cyan\", [ \"h-19.02\", \"v119.09\", \"h-142.94\" ] ],\n [ \"led1:A\", \"esp:8\", \"gray\", [ \"v80.81\", \"h210.16\" ] ],\n [ \"led1:C\", \"r1:2\", \"black\", [ \"v93.24\", \"h119.4\" ] ],\n [ \"esp:GND.8\", \"r1:1\", \"black\", [ \"v0\" ] ],\n [ \"esp:10\", \"bz1:2\", \"white\", [ \"v-19.85\", \"h-127.94\" ] ],\n [ \"bz1:1\", \"esp:GND.4\", \"black\", [ \"h7.46\", \"v-0.31\", \"h107.6\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32-S2", + "input": "void setup() {\n // put your setup code here, to run once:\n Serial.begin(115200);\n Serial.println(\"Hello, ESP32-S2!\");\n}\n\nvoid loop() {\n // put your main code here, to run repeatedly:\n delay(10); // this speeds up the simulation\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [ { \"id\": \"esp\", \"type\": \"board-esp32-s2-devkitm-1\" } ],\n \"connections\": [ [ \"esp:TX\", \"$serialMonitor:RX\", \"\" ], [ \"esp:RX\", \"$serialMonitor:TX\", \"\" ] ]\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32-S3", + "input": "void setup() {\n // put your setup code here, to run once:\n Serial.begin(115200);\n Serial.println(\"Hello, ESP32-S3!\");\n}\n\nvoid loop() {\n // put your main code here, to run repeatedly:\n delay(10); // this speeds up the simulation\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [ { \"id\": \"esp\", \"type\": \"board-esp32-s3-devkitc-1\" } ],\n \"connections\": [ [ \"esp:TX\", \"$serialMonitor:RX\", \"\" ], [ \"esp:RX\", \"$serialMonitor:TX\", \"\" ] ]\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32-C3", + "input": "void setup() {\n // put your setup code here, to run once:\n Serial.begin(115200);\n Serial.println(\"Hello, ESP32-C3!\");\n}\n\nvoid loop() {\n // put your main code here, to run repeatedly:\n delay(10); // this speeds up the simulation\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [ { \"id\": \"esp\", \"type\": \"board-esp32-c3-devkitm-1\" } ],\n \"connections\": [ [ \"esp:TX\", \"$serialMonitor:RX\", \"\" ], [ \"esp:RX\", \"$serialMonitor:TX\", \"\" ] ]\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32-C6", + "input": "void setup() {\n // put your setup code here, to run once:\n Serial.begin(115200);\n Serial.println(\"Hello, ESP32-C6!\");\n}\n\nvoid loop() {\n // put your main code here, to run repeatedly:\n delay(10); // this speeds up the simulation\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [ { \"id\": \"esp\", \"type\": \"board-esp32-c6-devkitc-1\" } ],\n \"connections\": [ [ \"esp:TX\", \"$serialMonitor:RX\", \"\" ], [ \"esp:RX\", \"$serialMonitor:TX\", \"\" ] ]\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32-H2", + "input": "void setup() {\n // put your setup code here, to run once:\n Serial.begin(115200);\n Serial.println(\"Hello, ESP32-H2!\");\n}\n\nvoid loop() {\n // put your main code here, to run repeatedly:\n delay(10); // this speeds up the simulation\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [ { \"id\": \"esp\", \"type\": \"board-esp32-h2-devkitm-1\" } ],\n \"connections\": [ [ \"esp:TX\", \"$serialMonitor:RX\", \"\" ], [ \"esp:RX\", \"$serialMonitor:TX\", \"\" ] ]\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32-S3-box3", + "input": "/*\n ESP32-S3-BOX + Adafruit_ILI9341 Example\n \n https://wokwi.com/projects/399780007361137665\n*/\n\n#include \"SPI.h\"\n#include \"Adafruit_GFX.h\"\n#include \"Adafruit_ILI9341.h\"\n\n#define TFT_DC 4\n#define TFT_CS 5\n#define TFT_MOSI 6\n#define TFT_CLK 7\n#define TFT_CTRL 45\n#define TFT_RST 48\n\nAdafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST);\n\nvoid setup() {\n Serial.begin(115200); \n Serial.println(\"Welcome to Wokwi, ESP32-S3-BOX-3\");\n \n pinMode(TFT_CTRL, OUTPUT);\n digitalWrite(TFT_CTRL, HIGH);\n\n tft.begin();\n\n // Configure the direction of the display\n const uint8_t mode = 0xc8;\n tft.sendCommand(ILI9341_MADCTL, &mode, 1);\n\n tft.setCursor(88, 60);\n tft.setTextColor(ILI9341_RED);\n tft.setTextSize(3);\n tft.println(\"S3-BOX-3\");\n}\n\nconst uint32_t colors[] = {\n ILI9341_GREEN,\n ILI9341_CYAN,\n ILI9341_MAGENTA,\n ILI9341_YELLOW,\n};\nuint8_t colorIndex = 0;\n\nvoid loop() {\n tft.setTextSize(2);\n tft.setCursor(36, 106);\n tft.setTextColor(colors[colorIndex++ % 4]);\n tft.println(\"Welcome to Wokwi!\");\n delay(250);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"board-esp32-s3-box-3\",\n \"id\": \"esp32\",\n \"top\": -24.91,\n \"left\": -388.54,\n \"attrs\": { \"psramSize\": \"16\", \"flashSize\": \"16\" }\n }\n ],\n \"connections\": [ [ \"$serialMonitor:RX\", \"esp32:G14\", \"\", [] ], [ \"$serialMonitor:TX\", \"esp32:G11\", \"\", [] ] ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for core-s3", + "input": "#include \"SPI.h\"\n#include \"Adafruit_GFX.h\"\n#include \"Adafruit_ILI9341.h\"\n\n#define TFT_DC 35\n#define TFT_CS 3\n#define TFT_MOSI 37\n#define TFT_CLK 36\n\n\nAdafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK);\n\nvoid setup() {\n Serial.begin(115200); \n Serial.println(\"Welcome to Wokwi, CORE-S3\");\n \n \n tft.begin();\n\n // Configure the direction of the display\n const uint8_t mode = 0xc8;\n tft.sendCommand(ILI9341_MADCTL, &mode, 1);\n\n tft.setCursor(88, 60);\n tft.setTextColor(ILI9341_RED);\n tft.setTextSize(3);\n tft.println(\"CORE-S3\");\n}\n\nconst uint32_t colors[] = {\n ILI9341_GREEN,\n ILI9341_CYAN,\n ILI9341_MAGENTA,\n ILI9341_YELLOW,\n};\nuint8_t colorIndex = 0;\n\nvoid loop() {\n tft.setTextSize(2);\n tft.setCursor(36, 106);\n tft.setTextColor(colors[colorIndex++ % 4]);\n tft.println(\"Welcome to Wokwi!\");\n delay(250);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Ambitious maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"board-m5stack-core-s3\",\n \"id\": \"board\",\n \"top\": -179.23,\n \"left\": -62.59,\n \"attrs\": {\n \"serialInterface\": \"USB_SERIAL_JTAG\"\n }\n }\n ],\n \"connections\": [\n [\n \"$serialMonitor:RX\",\n \"board:G43\",\n \"\",\n []\n ],\n [\n \"$serialMonitor:TX\",\n \"board:G44\",\n \"\",\n []\n ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for RGB LED sequence using XIOA-ESP32-C3", + "input": "void setup() {\n Serial.begin(115200);\n pinMode(D2, OUTPUT);\n pinMode(D3, OUTPUT);\n pinMode(D4, OUTPUT);\n\n Serial.println(\"\");\n Serial.println(\"Hello, XIAO ESP32-C3!\");\n Serial.println(\"Welcome to Wokwi :-)\");\n}\n\nvoid loop() {\n Serial.println(\"Red\");\n digitalWrite(D2, HIGH);\n delay(500);\n digitalWrite(D2, LOW);\n\n Serial.println(\"Green\");\n digitalWrite(D3, HIGH);\n delay(500);\n digitalWrite(D3, LOW);\n\n Serial.println(\"Blue\");\n digitalWrite(D4, HIGH);\n delay(500);\n digitalWrite(D4, LOW);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-xiao-esp32-c3\", \"id\": \"esp\", \"top\": 38.97, \"left\": 13.78, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": 6, \"left\": -73, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 147.95,\n \"left\": -57.6,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": 15.6,\n \"left\": -101.8,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 167.15,\n \"left\": -57.6,\n \"attrs\": { \"value\": \"1000\" }\n },\n { \"type\": \"wokwi-junction\", \"id\": \"j1\", \"top\": 148.8, \"left\": 24, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": 25.2,\n \"left\": -130.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 186.35,\n \"left\": -57.6,\n \"attrs\": { \"value\": \"1000\" }\n }\n ],\n \"connections\": [\n [ \"esp:D2\", \"led1:A\", \"green\", [ \"h0\" ] ],\n [ \"led1:C\", \"r1:1\", \"black\", [ \"v0\" ] ],\n [ \"esp:D3\", \"led2:A\", \"green\", [ \"h0\" ] ],\n [ \"led2:C\", \"r2:1\", \"black\", [ \"v0\" ] ],\n [ \"r2:2\", \"j1:J\", \"black\", [ \"v0\", \"h27.6\" ] ],\n [ \"j1:J\", \"r1:2\", \"black\", [ \"v0\" ] ],\n [ \"esp:GND\", \"j1:J\", \"black\", [ \"h19.82\", \"v86.4\" ] ],\n [ \"led3:A\", \"esp:D4\", \"green\", [ \"v0\" ] ],\n [ \"led3:C\", \"r3:1\", \"black\", [ \"v0\" ] ],\n [ \"j1:J\", \"r3:2\", \"black\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for RGB LED sequence with XIAO-ESP32-C6", + "input": "void setup() {\n Serial.begin(115200);\n pinMode(D2, OUTPUT);\n pinMode(D3, OUTPUT);\n pinMode(D4, OUTPUT);\n\n Serial.println(\"\");\n Serial.println(\"Hello, XIAO ESP32-C6!\");\n Serial.println(\"Welcome to Wokwi :-)\");\n}\n\nvoid loop() {\n Serial.println(\"Red\");\n digitalWrite(D2, HIGH);\n delay(500);\n digitalWrite(D2, LOW);\n\n Serial.println(\"Green\");\n digitalWrite(D3, HIGH);\n delay(500);\n digitalWrite(D3, LOW);\n\n Serial.println(\"Blue\");\n digitalWrite(D4, HIGH);\n delay(500);\n digitalWrite(D4, LOW);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-xiao-esp32-c6\", \"id\": \"esp\", \"top\": 38.97, \"left\": 13.78, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": 6, \"left\": -73, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 147.95,\n \"left\": -57.6,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": 15.6,\n \"left\": -101.8,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 167.15,\n \"left\": -57.6,\n \"attrs\": { \"value\": \"1000\" }\n },\n { \"type\": \"wokwi-junction\", \"id\": \"j1\", \"top\": 148.8, \"left\": 24, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": 25.2,\n \"left\": -130.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 186.35,\n \"left\": -57.6,\n \"attrs\": { \"value\": \"1000\" }\n }\n ],\n \"connections\": [\n [ \"esp:D2\", \"led1:A\", \"green\", [ \"h0\" ] ],\n [ \"led1:C\", \"r1:1\", \"black\", [ \"v0\" ] ],\n [ \"esp:D3\", \"led2:A\", \"green\", [ \"h0\" ] ],\n [ \"led2:C\", \"r2:1\", \"black\", [ \"v0\" ] ],\n [ \"r2:2\", \"j1:J\", \"black\", [ \"v0\", \"h27.6\" ] ],\n [ \"j1:J\", \"r1:2\", \"black\", [ \"v0\" ] ],\n [ \"esp:GND\", \"j1:J\", \"black\", [ \"h19.82\", \"v86.4\" ] ],\n [ \"led3:A\", \"esp:D4\", \"green\", [ \"v0\" ] ],\n [ \"led3:C\", \"r3:1\", \"black\", [ \"v0\" ] ],\n [ \"j1:J\", \"r3:2\", \"black\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for RGB LED sequence with XIOA-ESP32-S3", + "input": "void setup() {\n Serial.begin(115200);\n pinMode(D2, OUTPUT);\n pinMode(D3, OUTPUT);\n pinMode(D4, OUTPUT);\n\n Serial.println(\"\");\n Serial.println(\"Hello, XIAO ESP32-S3!\");\n Serial.println(\"Welcome to Wokwi :-)\");\n}\n\nvoid loop() {\n Serial.println(\"Red\");\n digitalWrite(D2, HIGH);\n delay(500);\n digitalWrite(D2, LOW);\n\n Serial.println(\"Green\");\n digitalWrite(D3, HIGH);\n delay(500);\n digitalWrite(D3, LOW);\n\n Serial.println(\"Blue\");\n digitalWrite(D4, HIGH);\n delay(500);\n digitalWrite(D4, LOW);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-xiao-esp32-s3\", \"id\": \"esp\", \"top\": 38.97, \"left\": 13.78, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": 6, \"left\": -73, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 147.95,\n \"left\": -57.6,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": 15.6,\n \"left\": -101.8,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 167.15,\n \"left\": -57.6,\n \"attrs\": { \"value\": \"1000\" }\n },\n { \"type\": \"wokwi-junction\", \"id\": \"j1\", \"top\": 148.8, \"left\": 24, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": 25.2,\n \"left\": -130.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 186.35,\n \"left\": -57.6,\n \"attrs\": { \"value\": \"1000\" }\n }\n ],\n \"connections\": [\n [ \"esp:D2\", \"led1:A\", \"green\", [ \"h0\" ] ],\n [ \"led1:C\", \"r1:1\", \"black\", [ \"v0\" ] ],\n [ \"esp:D3\", \"led2:A\", \"green\", [ \"h0\" ] ],\n [ \"led2:C\", \"r2:1\", \"black\", [ \"v0\" ] ],\n [ \"r2:2\", \"j1:J\", \"black\", [ \"v0\", \"h27.6\" ] ],\n [ \"j1:J\", \"r1:2\", \"black\", [ \"v0\" ] ],\n [ \"esp:GND\", \"j1:J\", \"black\", [ \"h19.82\", \"v86.4\" ] ],\n [ \"led3:A\", \"esp:D4\", \"green\", [ \"v0\" ] ],\n [ \"led3:C\", \"r3:1\", \"black\", [ \"v0\" ] ],\n [ \"j1:J\", \"r3:2\", \"black\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32 wifi", + "input": "#include \"WiFi.h\"\n\nvoid setup() {\nSerial.begin(115200);\nSerial.println(\"Initializing WiFi...\");\nWiFi.mode(WIFI_STA);\nSerial.println(\"Setup done!\");\n}\nvoid loop() {\nSerial.println(\"Scanning...\");\n// WiFi.scanNetworks will return the number of networks found\nint n = WiFi.scanNetworks();\nSerial.println(\"Scan done!\");\nif (n == 0) {\nSerial.println(\"No networks found.\");\n} else {\nSerial.println();\nSerial.print(n);\nSerial.println(\" networks found\");\nfor (int i = 0; i < n; ++i) {\n// Print SSID and RSSI for each network found\nSerial.print(i + 1);\nSerial.print(\": \");\nSerial.print(WiFi.SSID(i));\nSerial.print(\" (\");\nSerial.print(WiFi.RSSI(i));\nSerial.print(\")\");\nSerial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? \" \" : \"*\");\ndelay(10);\n}\n}\nSerial.println(\"\");\n// Wait a bit before scanning again\ndelay(5000); \n}", + "output": "{\n \"version\": 1,\n \"author\": \"Carl B\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-half\", \"id\": \"bb2\", \"top\": 198.6, \"left\": -35.6, \"attrs\": {} },\n {\n \"type\": \"board-esp32-devkit-c-v4\",\n \"id\": \"esp\",\n \"top\": 219.14,\n \"left\": 32.5,\n \"rotate\": 90,\n \"attrs\": {}\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"esp:GND.2\", \"bb2:bn.25\", \"black\", [ \"v38.4\", \"h144\", \"v-19.2\" ] ],\n [ \"esp:3V3\", \"bb2:bp.25\", \"red\", [ \"v0.15\", \"h134.4\", \"v105.6\" ] ],\n [ \"esp:12\", \"bb2:7t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:13\", \"bb2:5t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:14\", \"bb2:8t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:25\", \"bb2:11t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:26\", \"bb2:10t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:27\", \"bb2:9t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:32\", \"bb2:13t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:33\", \"bb2:12t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:34\", \"bb2:15t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:35\", \"bb2:14t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:3V3\", \"bb2:19t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:EN\", \"bb2:18t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:VP\", \"bb2:17t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:VN\", \"bb2:16t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:GND.1\", \"bb2:6t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:D2\", \"bb2:4t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:D3\", \"bb2:3t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:CMD\", \"bb2:2t.d\", \"\", [ \"$bb\" ] ],\n [ \"esp:5V\", \"bb2:1t.d\", \"\", [ \"$bb\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for ultrasonic distance measurement using LED indicators(ESP32)", + "input": "// Define GPIO pins for Ultrasonic Sensor and LED\n#define TRIG_PIN 12 // GPIO for Trig pin\n#define ECHO_PIN 14 // GPIO for Echo pin\n\n#define RED_LED 27\n#define YELLOW_LED 26\n#define GREEN_LED 25\n\nvoid setup() {\n // Set GPIO pins\n pinMode(TRIG_PIN, OUTPUT);\n pinMode(ECHO_PIN, INPUT);\n pinMode(RED_LED, OUTPUT);\n pinMode(YELLOW_LED, OUTPUT);\n pinMode(GREEN_LED, OUTPUT);\n\n // Start Serial Monitor\n Serial.begin(115200);\n}\n\nvoid loop() {\n // Measure distance\n float distance = measureDistance();\n\n // Display distance on Serial Monitor\n Serial.print(\"Distance: \");\n Serial.print(distance);\n Serial.println(\" cm\");\n\n // Check distance\n if (distance < 100) {\n digitalWrite(GREEN_LED, HIGH); // Turn on LED\n } else {\n digitalWrite(GREEN_LED, LOW); // Turn off LED\n }\n if (distance > 100) {\n digitalWrite(YELLOW_LED, HIGH);\n } else {\n digitalWrite(YELLOW_LED, LOW);\n }\n if (distance > 202) {\n digitalWrite(RED_LED, HIGH);\n } else {\n digitalWrite(RED_LED, LOW);\n }\n\n delay(500); // Delay for 500 milliseconds\n}\n\n// Function to measure distance\nfloat measureDistance() {\n // Send Trig signal\n digitalWrite(TRIG_PIN, LOW);\n delayMicroseconds(2);\n digitalWrite(TRIG_PIN, HIGH);\n delayMicroseconds(10);\n digitalWrite(TRIG_PIN, LOW);\n\n // Read Echo time\n long duration = pulseIn(ECHO_PIN, HIGH);\n\n // Calculate distance (unit: centimeters)\n float distance = duration * 0.034 / 2;\n\n return distance;\n}", + "output": "{\n \"version\": 1,\n \"author\": \"KAMONPHOB WONGPAN\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-half\", \"id\": \"bb1\", \"top\": -70.2, \"left\": -150.8, \"attrs\": {} },\n {\n \"type\": \"board-esp32-devkit-c-v4\",\n \"id\": \"esp\",\n \"top\": 103.94,\n \"left\": -92.3,\n \"rotate\": 90,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-hc-sr04\", \"id\": \"ultrasonic1\", \"top\": -94.5, \"left\": -138.5, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -42, \"left\": 71, \"attrs\": { \"color\": \"yellow\" } },\n { \"type\": \"wokwi-led\", \"id\": \"led2\", \"top\": -42, \"left\": 42.2, \"attrs\": { \"color\": \"red\" } },\n { \"type\": \"wokwi-led\", \"id\": \"led3\", \"top\": -42, \"left\": 99.8, \"attrs\": { \"color\": \"green\" } },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 33.6,\n \"left\": 37.85,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 33.6,\n \"left\": 66.65,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 33.6,\n \"left\": 95.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"ultrasonic1:VCC\", \"bb1:bp.4\", \"red\", [ \"v28.8\", \"h-19.2\" ] ],\n [ \"bb1:bp.1\", \"esp:5V\", \"green\", [ \"v-0.9\", \"h-17.6\" ] ],\n [ \"bb1:bn.1\", \"esp:GND.1\", \"black\", [ \"v27.5\", \"h30.4\" ] ],\n [ \"bb1:8t.e\", \"esp:12\", \"orange\", [ \"v124.8\", \"h-19.2\" ] ],\n [ \"bb1:9t.e\", \"esp:14\", \"gold\", [ \"v124.8\", \"h-19.2\" ] ],\n [ \"bb1:10t.e\", \"bb1:bn.6\", \"purple\", [ \"v0\" ] ],\n [ \"bb1:tn.16\", \"bb1:20t.a\", \"green\", [ \"v0\" ] ],\n [ \"bb1:tn.19\", \"bb1:23t.a\", \"green\", [ \"v0\" ] ],\n [ \"bb1:tn.21\", \"bb1:26t.a\", \"green\", [ \"v0\" ] ],\n [ \"r1:2\", \"esp:27\", \"red\", [ \"h-96\", \"v85.2\", \"h-28.8\" ] ],\n [ \"r3:2\", \"esp:25\", \"green\", [ \"h0\", \"v85.2\", \"h-153.6\" ] ],\n [ \"bb1:tn.25\", \"esp:GND.2\", \"black\", [ \"v-0.1\", \"h49.6\", \"v297.6\" ] ],\n [ \"r2:2\", \"esp:26\", \"gold\", [ \"v8.4\", \"h-76.8\", \"v69.6\", \"h-67.2\", \"v16.65\" ] ],\n [ \"ultrasonic1:VCC\", \"bb1:7t.c\", \"\", [ \"$bb\" ] ],\n [ \"ultrasonic1:TRIG\", \"bb1:8t.c\", \"\", [ \"$bb\" ] ],\n [ \"ultrasonic1:ECHO\", \"bb1:9t.c\", \"\", [ \"$bb\" ] ],\n [ \"ultrasonic1:GND\", \"bb1:10t.c\", \"\", [ \"$bb\" ] ],\n [ \"led1:A\", \"bb1:24t.c\", \"\", [ \"$bb\" ] ],\n [ \"led1:C\", \"bb1:23t.c\", \"\", [ \"$bb\" ] ],\n [ \"led2:A\", \"bb1:21t.c\", \"\", [ \"$bb\" ] ],\n [ \"led2:C\", \"bb1:20t.c\", \"\", [ \"$bb\" ] ],\n [ \"led3:A\", \"bb1:27t.c\", \"\", [ \"$bb\" ] ],\n [ \"led3:C\", \"bb1:26t.c\", \"\", [ \"$bb\" ] ],\n [ \"r1:1\", \"bb1:21t.d\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"bb1:21b.h\", \"\", [ \"$bb\" ] ],\n [ \"r2:1\", \"bb1:24t.d\", \"\", [ \"$bb\" ] ],\n [ \"r2:2\", \"bb1:24b.h\", \"\", [ \"$bb\" ] ],\n [ \"r3:1\", \"bb1:27t.d\", \"\", [ \"$bb\" ] ],\n [ \"r3:2\", \"bb1:27b.h\", \"\", [ \"$bb\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Temperature and Humidity using DHT11 with ESP32", + "input": "#include \"DHT.h\"\n#include \n#include \n#include \n\n#define R_LED 26\n#define B_LED 25\n#define DHTPIN 19 \n\n#define DHTTYPE DHT22 \n\n#define SCREEN_WIDTH 128 \n#define SCREEN_HEIGHT 64 \n\n#define OLED_RESET -1 \n\nDHT dht(DHTPIN, DHTTYPE);\n\nAdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);\n\nvoid setup() {\n\n Serial.begin(9600);\n pinMode(R_LED, OUTPUT);\n digitalWrite(R_LED, LOW);\n pinMode(B_LED, OUTPUT);\n digitalWrite(B_LED, LOW);\n\n\n dht.begin();\n\n display.begin(SSD1306_SWITCHCAPVCC, 0x3c); \n display.clearDisplay(); \n display.setTextSize(1); \n display.setTextColor(WHITE);\n display.setCursor(0,0); \n display.println(\" OLED 0.96 TESTER\");\n display.display();\n\n}\n\nvoid loop() {\n\n delay(1000);\n\n float h = dht.readHumidity();\n float t = dht.readTemperature();\n\n if (isnan(h) || isnan(t)) {\n Serial.println(F(\"Failed to read from DHT sensor!\"));\n return;\n }\n\n display.clearDisplay();\n\n display.setCursor(0,2); \n display.print(\"Temp : \");\n display.print(String(t));\n display.print(\" %\");\n\n display.setCursor(0,12); \n display.print(\"Humid : \");\n display.print(String(h));\n display.print(\" *C\");\n\n display.display();\n\n \n if(t > 50){\n digitalWrite(R_LED, HIGH);\n }else if(h > 50){\n digitalWrite(B_LED, HIGH);\n }else if (t < 49){\n digitalWrite(R_LED, LOW);\n }else if (h < 49){\n digitalWrite(B_LED, LOW);\n }\n\n}", + "output": "{\n \"version\": 1,\n \"author\": \"ADITHEP TONGRUENG\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-half\", \"id\": \"bb1\", \"top\": -147, \"left\": -160.4, \"attrs\": {} },\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 76.8, \"left\": -52.76, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": -118.8,\n \"left\": -82.6,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -118.8,\n \"left\": -121,\n \"attrs\": { \"color\": \"red\" }\n },\n { \"type\": \"wokwi-dht22\", \"id\": \"dht1\", \"top\": -143.7, \"left\": 42.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": -43.2,\n \"left\": -86.95,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"470\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": -43.2,\n \"left\": -125.35,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"470\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": -14.95,\n \"left\": 8.2,\n \"rotate\": 180,\n \"attrs\": { \"value\": \"4700\" }\n },\n {\n \"type\": \"board-ssd1306\",\n \"id\": \"oled1\",\n \"top\": 166.34,\n \"left\": 115.43,\n \"attrs\": { \"i2cAddress\": \"0x3c\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"bb1:21b.g\", \"bb1:16b.g\", \"green\", [ \"v0\" ] ],\n [ \"bb1:16b.j\", \"bb1:bp.13\", \"red\", [ \"v0\" ] ],\n [ \"esp:GND.2\", \"bb1:bn.25\", \"black\", [ \"v0\", \"h96\" ] ],\n [ \"esp:3V3\", \"bb1:bp.1\", \"red\", [ \"h-95.85\", \"v-38.4\" ] ],\n [ \"bb1:4t.e\", \"bb1:bn.3\", \"black\", [ \"v0\" ] ],\n [ \"bb1:8t.e\", \"bb1:bn.6\", \"black\", [ \"v0\" ] ],\n [ \"bb1:22b.j\", \"esp:19\", \"blue\", [ \"v163.2\", \"h-9.6\" ] ],\n [ \"oled1:GND\", \"bb1:bn.22\", \"black\", [ \"v-28.8\", \"h-28.8\" ] ],\n [ \"oled1:VCC\", \"bb1:bp.21\", \"red\", [ \"v-76.8\", \"h-57.45\" ] ],\n [ \"esp:22\", \"oled1:SCL\", \"cyan\", [ \"h0\" ] ],\n [ \"esp:21\", \"oled1:SDA\", \"magenta\", [ \"h134.4\" ] ],\n [ \"esp:26\", \"bb1:5b.j\", \"green\", [ \"h0\" ] ],\n [ \"esp:25\", \"bb1:9b.j\", \"green\", [ \"v0\", \"h-28.65\", \"v-163.2\", \"h19.2\" ] ],\n [ \"bb1:24b.j\", \"bb1:bn.20\", \"black\", [ \"v0\" ] ],\n [ \"led2:A\", \"bb1:5t.c\", \"\", [ \"$bb\" ] ],\n [ \"led2:C\", \"bb1:4t.c\", \"\", [ \"$bb\" ] ],\n [ \"dht1:VCC\", \"bb1:21b.f\", \"\", [ \"$bb\" ] ],\n [ \"dht1:SDA\", \"bb1:22b.f\", \"\", [ \"$bb\" ] ],\n [ \"dht1:NC\", \"bb1:23b.f\", \"\", [ \"$bb\" ] ],\n [ \"dht1:GND\", \"bb1:24b.f\", \"\", [ \"$bb\" ] ],\n [ \"r1:1\", \"bb1:9t.d\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"bb1:9b.h\", \"\", [ \"$bb\" ] ],\n [ \"r2:1\", \"bb1:5t.d\", \"\", [ \"$bb\" ] ],\n [ \"r2:2\", \"bb1:5b.h\", \"\", [ \"$bb\" ] ],\n [ \"r3:1\", \"bb1:22b.h\", \"\", [ \"$bb\" ] ],\n [ \"r3:2\", \"bb1:16b.h\", \"\", [ \"$bb\" ] ],\n [ \"led1:A\", \"bb1:9t.c\", \"\", [ \"$bb\" ] ],\n [ \"led1:C\", \"bb1:8t.c\", \"\", [ \"$bb\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Ultrasoni distamce measurement using ESP32", + "input": "#include \nLiquidCrystal_I2C lcd(0x27, 16, 2);\n#define TRIG_PIN 26\n#define ECHO_PIN 25\n\nfloat duration_us, distance_cm;\n\nvoid setup(){\n lcd.init();\n lcd.backlight();\n pinMode(TRIG_PIN, OUTPUT);\n pinMode(ECHO_PIN, INPUT);\n}\nvoid loop()\n{\n digitalWrite(TRIG_PIN, HIGH );\n delayMicroseconds(10);\n digitalWrite(TRIG_PIN, LOW);\n\n duration_us = pulseIn(ECHO_PIN, HIGH);\n\n distance_cm = 0.017* duration_us;\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.print(\"Distance:\");\n lcd.print(distance_cm);\n delay(500);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"manlika Phunut\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": -9.6, \"left\": -4.76, \"attrs\": {} },\n {\n \"type\": \"wokwi-lcd1602\",\n \"id\": \"lcd1\",\n \"top\": -80,\n \"left\": 149.6,\n \"attrs\": { \"pins\": \"i2c\" }\n },\n { \"type\": \"wokwi-hc-sr04\", \"id\": \"ultrasonic1\", \"top\": -56.1, \"left\": -215.3, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"ultrasonic1:VCC\", \"esp:5V\", \"red\", [ \"v0\" ] ],\n [ \"lcd1:VCC\", \"esp:5V\", \"red\", [ \"h-9.6\", \"v268.9\", \"h-153.6\", \"v-38.4\" ] ],\n [ \"lcd1:GND\", \"esp:GND.2\", \"black\", [ \"h0\" ] ],\n [ \"ultrasonic1:GND\", \"esp:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"ultrasonic1:TRIG\", \"esp:26\", \"blue\", [ \"v0\" ] ],\n [ \"ultrasonic1:ECHO\", \"esp:25\", \"purple\", [ \"v0\" ] ],\n [ \"lcd1:SDA\", \"esp:21\", \"yellow\", [ \"h-38.4\", \"v96.2\" ] ],\n [ \"lcd1:SCL\", \"esp:22\", \"magenta\", [ \"h-48\", \"v57.9\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for 8-bit counter", + "input": "#include \n\nconst int buttonPin = 14; // GPIO pin for button\nconst int ledPin1 = 26; // GPIO pin for first LED\nconst int ledPin2 = 25; // GPIO pin for second LED\nconst int ledPin3 = 33; // GPIO pin for third LED\n\nint buttonState = 0; // variable for reading the button status\nint lastButtonState = 0; // previous button state\nint clickCount = 0; // variable to count button clicks\nunsigned long lastDebounceTime = 0; // the last time the output pin was toggled\nunsigned long debounceDelay = 0; // the debounce time; increase if the output flickers\n\nvoid setup() {\n pinMode(buttonPin, INPUT);\n pinMode(ledPin1, OUTPUT);\n pinMode(ledPin2, OUTPUT);\n pinMode(ledPin3, OUTPUT);\n Serial.begin(115200);\n}\n\nvoid loop() {\n int reading = digitalRead(buttonPin);\n\n if (reading != lastButtonState) {\n lastDebounceTime = millis(); // reset the debouncing timer\n }\n\n if ((millis() - lastDebounceTime) > debounceDelay) {\n if (reading != buttonState) {\n buttonState = reading;\n\n if (buttonState == HIGH) {\n clickCount = (clickCount + 1) % 8; // increment and wrap click count\n Serial.println(clickCount);\n updateLEDs(); // immediately update the LEDs\n }\n }\n }\n\n lastButtonState = reading;\n}\n\nvoid updateLEDs() {\n // Reset all LEDs to LOW\n digitalWrite(ledPin1, LOW);\n digitalWrite(ledPin2, LOW);\n digitalWrite(ledPin3, LOW);\n\n // Update LEDs based on click count\n switch (clickCount) {\n case 1:\n digitalWrite(ledPin3, HIGH);\n break;\n case 2:\n digitalWrite(ledPin2, HIGH);\n break;\n case 3:\n digitalWrite(ledPin2, HIGH);\n digitalWrite(ledPin3, HIGH);\n break;\n case 4:\n digitalWrite(ledPin1, HIGH);\n break;\n case 5:\n digitalWrite(ledPin1, HIGH);\n digitalWrite(ledPin3, HIGH);\n break;\n case 6:\n digitalWrite(ledPin1, HIGH);\n digitalWrite(ledPin2, HIGH);\n break;\n case 7:\n digitalWrite(ledPin1, HIGH);\n digitalWrite(ledPin2, HIGH);\n digitalWrite(ledPin3, HIGH);\n break;\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": -38.4, \"left\": 72.04, \"attrs\": {} },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": -13,\n \"left\": -182.4,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": -99.6,\n \"left\": -101.8,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -99.6,\n \"left\": -63.4,\n \"attrs\": { \"color\": \"red\" }\n },\n { \"type\": \"wokwi-led\", \"id\": \"led3\", \"top\": -99.6, \"left\": -25, \"attrs\": { \"color\": \"red\" } }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"btn1:2.r\", \"esp:GND.1\", \"green\", [ \"h67.4\", \"v77\" ] ],\n [ \"esp:GND.3\", \"led1:C\", \"black\", [ \"h19.2\", \"v153.6\", \"h0\", \"v-9.6\", \"h-278.4\" ] ],\n [ \"esp:GND.3\", \"led2:C\", \"black\", [ \"h19.2\", \"v144\", \"h-240\" ] ],\n [ \"esp:GND.3\", \"led3:C\", \"black\", [ \"h28.8\", \"v144\", \"h-211.2\" ] ],\n [ \"esp:14\", \"btn1:1.r\", \"green\", [ \"h-172.65\", \"v-96\", \"h-19.2\" ] ],\n [ \"esp:26\", \"led1:A\", \"green\", [ \"h-153.45\", \"v0\" ] ],\n [ \"esp:25\", \"led2:A\", \"green\", [ \"v0\", \"h-143.85\" ] ],\n [ \"esp:33\", \"led3:A\", \"green\", [ \"h-76.65\", \"v-9.6\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32 base IoT system", + "input": "#include \n#include \n\n// WiFi credentials\nconst char* ssid = \"Wokwi-GUEST\";\nconst char* password = \"\";\n\n// MQTT server details\nconst char* mqttServer = \"broker.hivemq.com\";\nint mqttPort = 1883;\nconst char* mqttUser = \"\";\nconst char* mqttPassword = \"\";\nconst char* mqttClientID = \"ESP32Client\";\nconst char* topic = \"DEIOT/room/3395498B\";\n\n// Create WiFi and MQTT client objects\nWiFiClient wifiClient;\nPubSubClient client(wifiClient);\n\n// Define GPIO pins for LEDs and analog input\nconst int ledPin = 32;\nconst int yellowLedPin = 22;\nconst int analogPin = 12;\n\n// Timing variables for LED blinking and analog reading\nlong previousMillisR = 0;\nint intervalR = 1000;\nlong previousMillisAnalog = 0;\nint intervalAnalog = 2000;\n\nvoid setup() {\n // Set GPIO pins as outputs\n pinMode(ledPin, OUTPUT);\n pinMode(yellowLedPin, OUTPUT);\n\n // Start Serial Monitor\n Serial.begin(115200);\n\n // Connect to WiFi\n setupWiFi();\n\n // Set MQTT server and callback function\n client.setServer(mqttServer, mqttPort);\n client.setCallback(mqttCallback);\n\n // Connect to MQTT broker\n while (!client.connected()) {\n if (client.connect(mqttClientID)) {\n Serial.println(\"Connected to MQTT Broker!\");\n } else {\n Serial.print(\"MQTT connection failed. State: \");\n Serial.println(client.state());\n delay(2000);\n }\n }\n}\n\nvoid loop() {\n long currentMillis = millis();\n\n // Blink LED at regular intervals\n if (currentMillis - previousMillisR >= intervalR) {\n previousMillisR = currentMillis;\n digitalWrite(ledPin, !digitalRead(ledPin));\n }\n\n // Read analog value and publish to MQTT at regular intervals\n if (currentMillis - previousMillisAnalog >= intervalAnalog) {\n previousMillisAnalog = currentMillis;\n\n int analogValue = analogRead(analogPin);\n Serial.print(\"Analog Value from pin \");\n Serial.print(analogPin);\n Serial.print(\": \");\n Serial.println(analogValue);\n\n String payload = String(analogValue);\n if (client.publish(topic, payload.c_str())) {\n Serial.println(\"Published to MQTT\");\n } else {\n Serial.println(\"Failed to publish to MQTT\");\n }\n }\n\n // Handle MQTT client loop\n client.loop();\n}\n\nvoid setupWiFi() {\n Serial.println(\"Connecting to WiFi...\");\n WiFi.begin(ssid, password);\n\n while (WiFi.status() != WL_CONNECTED) {\n delay(1000);\n Serial.print(\".\");\n }\n\n Serial.println();\n Serial.print(\"Connected to WiFi with IP: \");\n Serial.println(WiFi.localIP());\n}\n\nvoid mqttCallback(char* topic, byte* payload, unsigned int length) {\n String message = \"\";\n for (int i = 0; i < length; i++) {\n message += (char)payload[i];\n }\n\n Serial.print(\"Message received on topic \");\n Serial.print(topic);\n Serial.print(\": \");\n Serial.println(message);\n\n int receivedValue = message.toInt();\n\n if (receivedValue < 1000) {\n digitalWrite(yellowLedPin, HIGH);\n Serial.println(\"yellow LED ON: Value is less than 1000\");\n } else {\n digitalWrite(yellowLedPin, LOW);\n Serial.println(\"yellow LED OFF: Value is greater than or equal to 1000\");\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 57.6, \"left\": 91.24, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -22.8,\n \"left\": -130.6,\n \"attrs\": { \"color\": \"red\" }\n },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot1\", \"top\": -20.5, \"left\": -48.2, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": 15.6,\n \"left\": 263,\n \"attrs\": { \"color\": \"yellow\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"led2:A\", \"esp:32\", \"green\", [ \"v0\" ] ],\n [ \"led2:C\", \"esp:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"pot1:SIG\", \"esp:12\", \"green\", [ \"v105.6\", \"h-0.4\", \"v38.4\" ] ],\n [ \"esp:GND.2\", \"pot1:GND\", \"black\", [ \"v-48\", \"h-134.4\", \"v28.8\", \"h-67.2\" ] ],\n [ \"pot1:VCC\", \"esp:3V3\", \"red\", [ \"v0\" ] ],\n [ \"led1:C\", \"esp:22\", \"green\", [ \"v0\" ] ],\n [ \"esp:GND.2\", \"led1:A\", \"black\", [ \"v0\", \"h96\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Smart energy monitoring system using ESP32", + "input": "#include \n#include \n#include \n#include \n#include \n\n#define SCREEN_WIDTH 128 // OLED width, in pixels\n#define SCREEN_HEIGHT 64 // OLED height, in pixels\n\n// OLED display object connected to I2C\nAdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);\n\n// WiFi credentials\nconst char* ssid = \"Wokwi-GUEST\";\nconst char* password = \"\";\n\n// ThingSpeak API information\nconst char* server = \"https://api.thingspeak.com\";\nconst char* apiKey = \"CDJEFTTGRAFUMV67\"; // Replace with your ThingSpeak Write API Key\n\nvoid setup() {\n Serial.begin(115200);\n\n if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {\n Serial.println(F(\"SSD1306 allocation failed\"));\n for (;;);\n }\n\n display.clearDisplay();\n display.setTextColor(WHITE);\n\n WiFi.begin(ssid, password);\n Serial.print(\"Connecting to WiFi\");\n while (WiFi.status() != WL_CONNECTED) {\n delay(1000);\n Serial.print(\".\");\n }\n Serial.println(\"\\nWiFi connected!\");\n}\n\nvoid sendDataToThingSpeak() {\n if (WiFi.status() == WL_CONNECTED) {\n HTTPClient http;\n String url = String(server) + \"/update?api_key=\" + apiKey;\n http.begin(url);\n int httpCode = http.GET();\n\n if (httpCode > 0) {\n Serial.println(\"Data sent to ThingSpeak successfully!\");\n } else {\n Serial.print(\"Error sending data: \");\n Serial.println(http.errorToString(httpCode).c_str());\n }\n\n http.end();\n } else {\n Serial.println(\"WiFi not connected! Unable to send data.\");\n }\n}\n\nvoid loop() {\n static unsigned long lastSendTime = 0;\n\n if (millis() - lastSendTime >= 10000) { // Send data every 10 seconds\n sendDataToThingSpeak();\n lastSendTime = millis();\n }\n\n display.clearDisplay();\n display.setTextSize(1);\n display.setCursor(0, 0);\n display.print(\"Sending data...\");\n display.display();\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Faiz Jefri\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-esp32-devkit-v1\", \"id\": \"esp\", \"top\": -33.7, \"left\": 14.2, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": -43.2,\n \"left\": 249.05,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 43.2,\n \"left\": 249.05,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"board-ssd1306\",\n \"id\": \"oled1\",\n \"top\": -131.26,\n \"left\": 345.83,\n \"attrs\": { \"i2cAddress\": \"0x3c\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 3.95,\n \"left\": 316.8,\n \"attrs\": { \"value\": \"100\" }\n },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot1\", \"top\": -106.9, \"left\": -173, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot2\", \"top\": 200.3, \"left\": -192.2, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"esp:TX0\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX0\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"r2:2\", \"esp:3V3\", \"red\", [ \"v46.8\", \"h-162.9\" ] ],\n [ \"r1:1\", \"esp:GND.1\", \"green\", [ \"h-57.6\", \"v105.6\" ] ],\n [ \"r2:1\", \"r1:2\", \"black\", [ \"h0\" ] ],\n [ \"oled1:SCL\", \"esp:D22\", \"black\", [ \"h-162.9\", \"v57.9\" ] ],\n [ \"oled1:SDA\", \"esp:D21\", \"black\", [ \"h-259.13\", \"v86.8\" ] ],\n [ \"r3:1\", \"r1:2\", \"black\", [ \"v0\", \"h-28.8\" ] ],\n [ \"pot1:VCC\", \"esp:VIN\", \"red\", [ \"v0\" ] ],\n [ \"pot1:GND\", \"esp:GND.2\", \"green\", [ \"v0\" ] ],\n [ \"pot2:VCC\", \"esp:VIN\", \"red\", [ \"v0\" ] ],\n [ \"pot2:GND\", \"esp:GND.2\", \"green\", [ \"v0\" ] ],\n [ \"pot1:SIG\", \"esp:D34\", \"black\", [ \"v0\" ] ],\n [ \"pot2:SIG\", \"esp:D35\", \"black\", [ \"v-124.8\", \"h-0.4\", \"v-38.4\" ] ],\n [ \"oled1:VCC\", \"esp:VIN\", \"red\", [ \"v-9.6\", \"h76.95\", \"v316.8\", \"h-451.2\" ] ],\n [ \"oled1:GND\", \"esp:GND.1\", \"green\", [ \"v-19.2\", \"h96\", \"v268.8\" ] ],\n [ \"esp:VP\", \"r3:2\", \"red\", [ \"h-19.2\", \"v-86.7\", \"h326.4\", \"v76.8\", \"h48\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for ESP32 based dual core system", + "input": "#include \n\n// Task handles for the two tasks\nTaskHandle_t Task1;\nTaskHandle_t Task2;\n\n// GPIO pins for the two 7-segment displays\nconst int seg1Pins[] = {2, 4, 5, 18, 19, 21, 22};\nconst int seg2Pins[] = {23, 25, 26, 27, 14, 12, 13};\n\n// Binary codes for digits 0-9 for 7-segment display\nconst byte digitCodes[] = {\n 0b00111111, // 0\n 0b00000110, // 1\n 0b01011011, // 2\n 0b01001111, // 3\n 0b01100110, // 4\n 0b01101101, // 5\n 0b01111101, // 6\n 0b00000111, // 7\n 0b01111111, // 8\n 0b01101111 // 9\n};\n\nvoid setup() {\n Serial.begin(115200);\n\n // Set all segment pins as outputs\n for (int i = 0; i < 7; i++) {\n pinMode(seg1Pins[i], OUTPUT);\n pinMode(seg2Pins[i], OUTPUT);\n }\n\n // Create Task1 on core 0\n xTaskCreatePinnedToCore(\n Task1code, // Function to implement the task\n \"Task1\", // Name of the task\n 10000, // Stack size in words\n NULL, // Task input parameter\n 1, // Priority of the task\n &Task1, // Task handle\n 0 // Core where the task should run\n );\n delay(500);\n\n // Create Task2 on core 1\n xTaskCreatePinnedToCore(\n Task2code, // Function to implement the task\n \"Task2\", // Name of the task\n 10000, // Stack size in words\n NULL, // Task input parameter\n 1, // Priority of the task\n &Task2, // Task handle\n 1 // Core where the task should run\n );\n delay(500);\n}\n\n// Function to display a number on a 7-segment display\nvoid displayNumber(const int *pins, int number) {\n byte code = digitCodes[number];\n for (int i = 0; i < 7; i++) {\n digitalWrite(pins[i], (code >> i) & 0x01);\n }\n}\n\n// Task1 code: Counts from 1 to 9 on the first 7-segment display\nvoid Task1code(void *pvParameters) {\n Serial.print(\"Task1 core: \");\n Serial.println(xPortGetCoreID());\n\n int count = 1;\n for (;;) {\n displayNumber(seg1Pins, count);\n count++;\n if (count > 9) count = 1;\n delay(1500); // Delay for 1.5 seconds\n }\n}\n\n// Task2 code: Counts from 9 to 1 on the second 7-segment display\nvoid Task2code(void *pvParameters) {\n Serial.print(\"Task2 core: \");\n Serial.println(xPortGetCoreID());\n\n int count = 9;\n for (;;) {\n displayNumber(seg2Pins, count);\n count--;\n if (count < 1) count = 9;\n delay(500); // Delay for 0.5 seconds\n }\n}\n\nvoid loop() {\n // Empty loop as tasks are running independently\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": -9.6, \"left\": 24.04, \"attrs\": {} },\n {\n \"type\": \"wokwi-7segment\",\n \"id\": \"sevseg1\",\n \"top\": 81.78,\n \"left\": 225.88,\n \"attrs\": { \"common\": \"cathode\" }\n },\n {\n \"type\": \"wokwi-7segment\",\n \"id\": \"sevseg2\",\n \"top\": 100.98,\n \"left\": -129.32,\n \"attrs\": { \"common\": \"cathode\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"sevseg1:B\", \"esp:4\", \"green\", [ \"v-8.76\", \"h-57.6\", \"v67.2\", \"h0\" ] ],\n [ \"sevseg1:A\", \"esp:2\", \"green\", [ \"v-18.36\", \"h-57.6\", \"v96\" ] ],\n [ \"sevseg1:C\", \"esp:5\", \"green\", [ \"v19.2\", \"h28.8\", \"v-115.2\", \"h-67.2\", \"v57.6\" ] ],\n [ \"sevseg1:D\", \"esp:18\", \"green\", [ \"v19.2\", \"h-48\", \"v-67.2\" ] ],\n [ \"sevseg1:E\", \"esp:19\", \"green\", [ \"v28.8\", \"h-48\", \"v-86.4\" ] ],\n [ \"sevseg1:F\", \"esp:21\", \"green\", [ \"v-37.56\", \"h-67.2\", \"v38.4\" ] ],\n [ \"sevseg1:G\", \"esp:22\", \"green\", [ \"v-47.16\", \"h-76.8\", \"v9.6\" ] ],\n [ \"sevseg1:COM.1\", \"esp:GND.3\", \"green\", [ \"h0\", \"v38.4\", \"h-96\", \"v-105.6\" ] ],\n [ \"sevseg2:A\", \"esp:23\", \"green\", [ \"v-143.16\", \"h230.4\", \"v67.2\" ] ],\n [ \"sevseg2:B\", \"esp:25\", \"green\", [ \"v0\" ] ],\n [ \"sevseg2:C\", \"esp:26\", \"green\", [ \"v19.2\", \"h19.2\", \"v-76.8\" ] ],\n [ \"sevseg2:D\", \"esp:27\", \"green\", [ \"v28.8\", \"h48\", \"v-76.8\" ] ],\n [ \"sevseg2:E\", \"esp:14\", \"green\", [ \"v38.4\", \"h67.2\", \"v-76.8\" ] ],\n [ \"sevseg2:F\", \"esp:12\", \"green\", [ \"v-18.36\", \"h67.2\", \"v57.6\" ] ],\n [ \"sevseg2:G\", \"esp:13\", \"green\", [ \"v0.84\", \"h-19.2\", \"v115.2\", \"h96\", \"v-57.6\" ] ],\n [ \"sevseg2:COM.1\", \"esp:GND.1\", \"green\", [ \"h0\", \"v9.6\", \"h86.4\", \"v-28.8\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for temperature measurement using NTC sensor(ESP32)", + "input": "const int tempPin = 14;\n#include \nLiquidCrystal lcd(18, 5, 17, 16, 4, 0);\nvoid setup() {\n Serial.begin(115200);\n Serial.println(\"Hello\");\n lcd.begin(16, 2);\n //lcd.print(\"ADC Example\");\n delay(1000);\n}\nvoid loop() {\n int adc = analogRead(tempPin);\n const float BETA = 3950.0; // should match the Beta Coefficient of the thermistor\n float temp = 1 / (log(1 / (4096.0 / adc - 1)) / BETA + 1.0 / 298.15) - 273.15;\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.print(\"temp: \");\n lcd.println(String(temp)+char(223)+\"C\");\n delay(2000);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"NAGA NANDHINI P\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 67.2, \"left\": -23.96, \"attrs\": {} },\n {\n \"type\": \"wokwi-ntc-temperature-sensor\",\n \"id\": \"ntc1\",\n \"top\": 117.8,\n \"left\": -202.2,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-lcd1602\", \"id\": \"lcd1\", \"top\": -92.57, \"left\": 35.2, \"attrs\": {} },\n { \"type\": \"wokwi-vcc\", \"id\": \"vcc1\", \"top\": 67.96, \"left\": 220.8, \"attrs\": {} },\n { \"type\": \"wokwi-gnd\", \"id\": \"gnd1\", \"top\": 76.8, \"left\": 95.4, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"lcd1:RS\", \"esp:18\", \"green\", [ \"v134.4\", \"h-18.9\" ] ],\n [ \"lcd1:E\", \"esp:5\", \"green\", [ \"v144\", \"h-38.4\" ] ],\n [ \"esp:0\", \"lcd1:D7\", \"green\", [ \"h115.2\", \"v-182.4\" ] ],\n [ \"lcd1:D6\", \"esp:4\", \"green\", [ \"v172.8\", \"h-105.4\" ] ],\n [ \"lcd1:D5\", \"esp:16\", \"green\", [ \"v163.2\", \"h-95.9\" ] ],\n [ \"lcd1:D4\", \"esp:17\", \"green\", [ \"v153.6\", \"h-86.4\" ] ],\n [ \"lcd1:RW\", \"lcd1:K\", \"green\", [ \"v19.2\", \"h105.5\" ] ],\n [ \"lcd1:RW\", \"gnd1:GND\", \"black\", [ \"v38.4\", \"h-0.1\" ] ],\n [ \"lcd1:A\", \"vcc1:VCC\", \"red\", [ \"v57.6\", \"h28.7\" ] ],\n [ \"ntc1:OUT\", \"esp:14\", \"green\", [ \"h28.8\", \"v38.3\" ] ],\n [ \"ntc1:GND\", \"esp:GND.1\", \"black\", [ \"h19.2\", \"v76.8\", \"h28.65\" ] ],\n [ \"ntc1:VCC\", \"esp:3V3\", \"red\", [ \"h28.8\", \"v-57.6\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Automatic light intensity control using LDR (ESP32)", + "input": "const int ldrPin = 34; // GPIO pin for LDR\nconst int ledPin = 32; // GPIO pin for LED\n\nvoid setup() {\n Serial.begin(115200);\n pinMode(ldrPin, INPUT);\n pinMode(ledPin, OUTPUT);\n}\n\nvoid loop() {\n int ldrValue = analogRead(ldrPin); // Read the LDR value\n Serial.print(\"LDR Value: \");\n Serial.println(ldrValue);\n\n // Map the LDR value to a PWM value (0-255)\n int ledBrightness = map(ldrValue, 0, 4095, 0, 255);\n analogWrite(ledPin, ledBrightness); // Set the LED brightness\n\n delay(100); // Delay for a short period\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-half\", \"id\": \"bb1\", \"top\": -22.2, \"left\": 12.4, \"attrs\": {} },\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": -19.2, \"left\": -110.36, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -3.6, \"left\": 42.2, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 72,\n \"left\": 37.85,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"330\" }\n },\n { \"type\": \"wokwi-photoresistor-sensor\", \"id\": \"ldr1\", \"top\": 204.8, \"left\": 0.8, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"esp:4\", \"bb1:4b.i\", \"green\", [ \"h76.8\" ] ],\n [ \"esp:GND.2\", \"bb1:3t.c\", \"red\", [ \"v0\", \"h19.2\", \"v38.4\" ] ],\n [ \"esp:15\", \"bb1:bp.3\", \"green\", [ \"v0\" ] ],\n [ \"bb1:bp.3\", \"ldr1:AO\", \"green\", [ \"v37.5\", \"h136\", \"v48\" ] ],\n [ \"led1:A\", \"bb1:4t.b\", \"\", [ \"$bb\" ] ],\n [ \"led1:C\", \"bb1:3t.b\", \"\", [ \"$bb\" ] ],\n [ \"r1:1\", \"bb1:4t.c\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"bb1:4b.g\", \"\", [ \"$bb\" ] ],\n [ \"esp:GND.2\", \"ldr1:GND\", \"black\", [ \"v0\", \"h57.6\", \"v182.4\", \"h163.2\", \"v38.4\" ] ],\n [ \"esp:5V\", \"ldr1:VCC\", \"red\", [ \"h-28.65\", \"v19.2\", \"h326.4\", \"v19.2\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for drawing game using a MAX7219 LED Dot Matrix", + "input": "#include \n\n#define\tMAX_DEVICES\t2\n\nconst int maxX = MAX_DEVICES * 8 - 1;\nconst int maxY = 7;\n\n#define\tCLK_PIN\t\t13\n#define\tDATA_PIN\t11\n#define\tCS_PIN\t\t10\n\n#define VERT_PIN A0\n#define HORZ_PIN A1\n#define SEL_PIN 2\n\nMD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, CS_PIN, MAX_DEVICES);\n\nint x = 0;\nint y = 0;\n\nvoid setup() {\n mx.begin();\n mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY / 2);\n mx.clear();\n\n pinMode(VERT_PIN, INPUT);\n pinMode(HORZ_PIN, INPUT);\n pinMode(SEL_PIN, INPUT_PULLUP);\n}\n\n// the loop function runs over and over again forever\nvoid loop() {\n int horz = analogRead(HORZ_PIN);\n int vert = analogRead(VERT_PIN);\n if (vert < 300) {\n y = min(y + 1, maxY);\n }\n if (vert > 700) {\n y = max(y - 1, 0);\n }\n if (horz > 700) {\n x = min(x + 1, maxX);\n }\n if (horz < 300) {\n x = max(x - 1, 0);\n }\n if (digitalRead(SEL_PIN) == LOW) {\n mx.clear();\n }\n mx.setPoint(y, x, true);\n mx.update();\n delay(100);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 120, \"left\": 20, \"attrs\": {} },\n {\n \"type\": \"wokwi-analog-joystick\",\n \"id\": \"joystick1\",\n \"top\": -9.72,\n \"left\": 264.35,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"matrix1\",\n \"top\": 9.03,\n \"left\": 52.86,\n \"attrs\": { \"chain\": \"2\" }\n }\n ],\n \"connections\": [\n [ \"joystick1:HORZ\", \"uno:A1\", \"green\", [ \"v0\", \"*\", \"v12\" ] ],\n [ \"joystick1:VERT\", \"uno:A0\", \"purple\", [ \"v0\", \"*\", \"v16\" ] ],\n [ \"joystick1:SEL\", \"uno:2\", \"blue\", [ \"v0\", \"*\", \"v-12\" ] ],\n [ \"joystick1:GND\", \"uno:GND.3\", \"black\", [ \"v0\", \"*\", \"v20\" ] ],\n [ \"joystick1:VCC\", \"uno:5V\", \"red\", [ \"v0\", \"*\", \"v24\" ] ],\n [ \"matrix1:CS\", \"uno:10\", \"blue\", [ \"h8\", \"*\", \"v-24\" ] ],\n [ \"matrix1:DIN\", \"uno:11\", \"green\", [ \"h12\", \"*\", \"v-20\" ] ],\n [ \"matrix1:CLK\", \"uno:13\", \"orange\", [ \"h4\", \"*\", \"v-28\" ] ],\n [ \"matrix1:GND\", \"uno:GND.1\", \"black\", [ \"h16\", \"*\", \"v-12\" ] ],\n [ \"joystick1:VCC\", \"matrix1:V+\", \"red\", [ \"v7.04\", \"h-38.02\", \"v-84.67\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for LED control using STM32", + "input": "#include \"main.h\"\n\nADC_HandleTypeDef hadc1; // ADC handle structure for ADC1\n\nvoid SystemClock_Config(void);\nstatic void MX_GPIO_Init(void);\nstatic void MX_ADC1_Init(void);\n\nint main(void)\n{\n int adcResult; // Variable to store ADC conversion result\n\n HAL_Init(); // Initialize the HAL library and reset peripherals\n\n SystemClock_Config(); // Configure the system clock\n\n MX_GPIO_Init(); // Initialize GPIO pins\n MX_ADC1_Init(); // Initialize ADC1\n\n while (1)\n {\n HAL_ADC_Start(&hadc1); // Start ADC conversion\n HAL_ADC_PollForConversion(&hadc1, 100); // Wait for ADC conversion to complete with a timeout of 100ms\n adcResult = HAL_ADC_GetValue(&hadc1); // Get the ADC conversion result\n HAL_ADC_Stop(&hadc1); // Stop the ADC conversion\n\n if (adcResult < 2048) // Check if the ADC result is below the threshold (mid-range for 12-bit ADC)\n HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, RESET); // Turn off the LED connected to PA5\n else\n HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, SET); // Turn on the LED connected to PA5\n }\n}\n\nvoid SystemClock_Config(void)\n{\n RCC_OscInitTypeDef RCC_OscInitStruct = {0}; // Structure to configure the oscillator\n RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; // Structure to configure the clock tree\n\n __HAL_FLASH_SET_LATENCY(FLASH_LATENCY_1); // Set flash latency for 1 wait state\n\n RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; // Use HSI oscillator\n RCC_OscInitStruct.HSIState = RCC_HSI_ON; // Enable HSI oscillator\n RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; // Set HSI division factor to 1\n RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; // Default HSI calibration\n if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)\n {\n Error_Handler(); // Handle configuration error\n }\n\n RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1; // Enable clocks for HCLK, SYSCLK, and PCLK1\n RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; // Use HSI as the system clock source\n RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; // No division for SYSCLK\n RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1; // No division for AHB\n RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1; // No division for APB1\n\n if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)\n {\n Error_Handler(); // Handle configuration error\n }\n}\n\nstatic void MX_ADC1_Init(void)\n{\n ADC_ChannelConfTypeDef sConfig = {0}; // Structure to configure ADC channels\n\n hadc1.Instance = ADC1; // Set the ADC instance to ADC1\n hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; // ADC clock prescaler\n hadc1.Init.Resolution = ADC_RESOLUTION_12B; // 12-bit resolution\n hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; // Right-aligned data\n hadc1.Init.ScanConvMode = ADC_SCAN_SEQ_FIXED; // Fixed sequence scanning mode\n hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; // End of conversion flag after each conversion\n hadc1.Init.LowPowerAutoWait = DISABLE; // Disable low power auto wait\n hadc1.Init.LowPowerAutoPowerOff = DISABLE; // Disable low power auto power-off\n hadc1.Init.ContinuousConvMode = DISABLE; // Single conversion mode\n hadc1.Init.NbrOfConversion = 1; // One conversion at a time\n hadc1.Init.DiscontinuousConvMode = DISABLE; // Disable discontinuous mode\n hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; // Start conversion via software\n hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; // No external trigger edge\n hadc1.Init.DMAContinuousRequests = DISABLE; // Disable continuous DMA requests\n hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; // Preserve data in case of overrun\n hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; // Sampling time of 1.5 ADC clock cycles\n hadc1.Init.OversamplingMode = DISABLE; // Disable oversampling\n hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; // High trigger frequency mode\n\n if (HAL_ADC_Init(&hadc1) != HAL_OK)\n {\n Error_Handler(); // Handle initialization error\n }\n\n sConfig.Channel = ADC_CHANNEL_0; // Select channel 0\n sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; // Rank the channel by number\n\n if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)\n {\n Error_Handler(); // Handle configuration error\n }\n}\n\nstatic void MX_GPIO_Init(void)\n{\n GPIO_InitTypeDef GPIO_InitStruct = {0}; // Structure to configure GPIO pins\n\n __HAL_RCC_GPIOA_CLK_ENABLE(); // Enable clock for GPIO port A\n\n HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); // Set PA5 to low (LED off)\n\n GPIO_InitStruct.Pin = GPIO_PIN_5; // Configure PA5\n GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Set mode to push-pull output\n GPIO_InitStruct.Pull = GPIO_NOPULL; // No internal pull-up or pull-down resistor\n GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; // Set output speed to low\n HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // Initialize PA5 with the configuration\n}\n\nvoid Error_Handler(void)\n{\n __disable_irq(); // Disable interrupts\n while (1) // Infinite loop to indicate error\n {\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"COD\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-st-nucleo-c031c6\", \"id\": \"nucleo\", \"top\": 0.83, \"left\": -0.98, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": 102, \"left\": 349.4, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 167.15,\n \"left\": 288,\n \"attrs\": { \"value\": \"1000\" }\n },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot1\", \"top\": 161.9, \"left\": -115.4, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"$serialMonitor:TX\", \"nucleo:PA3\", \"\", [] ],\n [ \"$serialMonitor:RX\", \"nucleo:PA2\", \"\", [] ],\n [ \"nucleo:3V3.2\", \"pot1:VCC\", \"green\", [ \"h-66.75\", \"v57.6\", \"h-37.6\" ] ],\n [ \"pot1:GND\", \"nucleo:PA14\", \"black\", [ \"v19.2\", \"h-48\", \"v-96\", \"h96\", \"v9.6\" ] ],\n [ \"nucleo:A0\", \"pot1:SIG\", \"gold\", [ \"h-47.55\", \"v9.6\", \"h-67.2\" ] ],\n [ \"nucleo:PA5\", \"r1:1\", \"green\", [ \"h0\" ] ],\n [ \"r1:2\", \"led1:A\", \"green\", [ \"v0\", \"h27.6\" ] ],\n [ \"nucleo:GND.9\", \"led1:C\", \"black\", [ \"h0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Traffic light using Raspberry pi pico", + "input": "#define RED 1\n#define YELLOW 5\n#define GREEN 9\n\nvoid setup() {\n pinMode(RED, OUTPUT);\n pinMode(YELLOW, OUTPUT);\n pinMode(GREEN, OUTPUT);\n}\n\nvoid loop() {\n digitalWrite(GREEN, HIGH);\n delay(3000);\n\n digitalWrite(GREEN, LOW);\n digitalWrite(YELLOW, HIGH);\n delay(500);\n\n digitalWrite(YELLOW, LOW);\n digitalWrite(RED, HIGH);\n delay(2000);\n\n digitalWrite(YELLOW, HIGH);\n delay(500);\n digitalWrite(YELLOW, LOW);\n digitalWrite(RED, LOW);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 20,\n \"left\": 60,\n \"attrs\": { \"env\": \"arduino-community\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": 3,\n \"left\": 0,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": 48,\n \"left\": 0,\n \"attrs\": { \"color\": \"yellow\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": 98,\n \"left\": 0,\n \"attrs\": { \"color\": \"green\" }\n }\n ],\n \"connections\": [\n [ \"pico:GND.1\", \"led1:C\", \"black\", [] ],\n [ \"pico:GP1\", \"led1:A\", \"blue\", [] ],\n [ \"pico:GND.2\", \"led2:C\", \"black\", [] ],\n [ \"pico:GP5\", \"led2:A\", \"blue\", [] ],\n [ \"pico:GND.3\", \"led3:C\", \"black\", [] ],\n [ \"pico:GP9\", \"led3:A\", \"blue\", [] ],\n [ \"$serialMonitor:RX\", \"pico:GP0\", \"\", [] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for LCD using Pi Pico", + "input": "// LCD1602 and Pi Pico!\n\n#include \n\nLiquidCrystal lcd(12, 11, 10, 9, 8, 7);\n\nvoid setup() {\n lcd.begin(16, 2);\n lcd.print(\"Hello World!\");\n\n lcd.setCursor(2, 1);\n lcd.print(\"> Pi Pico <\");\n}\n\nvoid loop() {\n delay(1); // Adding a delay() here speeds up the simulation\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 123.67,\n \"left\": 135.97,\n \"rotate\": 90,\n \"hide\": false,\n \"attrs\": { \"env\": \"arduino-community\" }\n },\n {\n \"type\": \"wokwi-lcd1602\",\n \"id\": \"lcd\",\n \"top\": -17.85,\n \"left\": 22.03,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 114.8,\n \"left\": 226.31,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"value\": \"220\" }\n }\n ],\n \"connections\": [\n [ \"pico:GND.1\", \"lcd:VSS\", \"black\", [ \"v-51\", \"*\", \"h0\", \"v18\" ] ],\n [ \"pico:GND.1\", \"lcd:K\", \"black\", [ \"v-51\", \"*\", \"h0\", \"v18\" ] ],\n [ \"pico:GND.1\", \"lcd:RW\", \"black\", [ \"v-51\", \"*\", \"h0\", \"v18\" ] ],\n [ \"pico:VSYS\", \"lcd:VDD\", \"red\", [ \"v16\", \"h-16\" ] ],\n [ \"pico:VSYS\", \"r1:2\", \"red\", [ \"v16\", \"h0\" ] ],\n [ \"r1:1\", \"lcd:A\", \"pink\", [] ],\n [ \"pico:GP12\", \"lcd:RS\", \"blue\", [ \"v-16\", \"*\", \"h0\", \"v20\" ] ],\n [ \"pico:GP11\", \"lcd:E\", \"purple\", [ \"v-20\", \"*\", \"h0\", \"v20\" ] ],\n [ \"pico:GP10\", \"lcd:D4\", \"green\", [ \"v-24\", \"*\", \"h0\", \"v20\" ] ],\n [ \"pico:GP9\", \"lcd:D5\", \"brown\", [ \"v-28\", \"*\", \"h0\", \"v20\" ] ],\n [ \"pico:GP8\", \"lcd:D6\", \"gold\", [ \"v-32\", \"*\", \"h0\", \"v20\" ] ],\n [ \"pico:GP7\", \"lcd:D7\", \"gray\", [ \"v-36\", \"*\", \"h0\", \"v20\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for Buzzer alaram using Pi Pico", + "input": "# Project objective: To test a passive buzzer to play an alarm sound at one second interval\n# if passive buzzer is used, import the Speaker class from picozero\nfrom picozero import Speaker\nfrom time import sleep\n\n# creating a Speaker object\nspeaker = Speaker(15)\n\n# continuously beep at 1 sec interval while the board has power\n# note: a passive buzzer can also be used to play different tones\nwhile True:\n speaker.on()\n sleep(1)\n speaker.off()\n sleep(1)", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-half\", \"id\": \"bb1\", \"top\": -3, \"left\": -112.4, \"attrs\": {} },\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 0.9,\n \"left\": -38.65,\n \"rotate\": 270,\n \"attrs\": { \"env\": \"micropython-20220618-v1.19.1\" }\n },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": 31.2,\n \"left\": 117,\n \"attrs\": { \"volume\": \"0.1\" }\n }\n ],\n \"connections\": [\n [ \"bb1:3b.j\", \"bb1:bn.2\", \"black\", [ \"v0\" ] ],\n [ \"bb1:25b.h\", \"bb1:bn.20\", \"black\", [ \"v0\" ] ],\n [ \"bb1:26b.j\", \"bb1:20b.j\", \"green\", [ \"v0\" ] ],\n [ \"pico:GP0\", \"bb1:1b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP1\", \"bb1:2b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GND.1\", \"bb1:3b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP2\", \"bb1:4b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP3\", \"bb1:5b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP4\", \"bb1:6b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP5\", \"bb1:7b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GND.2\", \"bb1:8b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP6\", \"bb1:9b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP7\", \"bb1:10b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP8\", \"bb1:11b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP9\", \"bb1:12b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GND.3\", \"bb1:13b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP10\", \"bb1:14b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP11\", \"bb1:15b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP12\", \"bb1:16b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP13\", \"bb1:17b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GND.4\", \"bb1:18b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP14\", \"bb1:19b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP15\", \"bb1:20b.h\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP16\", \"bb1:20t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP17\", \"bb1:19t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GND.5\", \"bb1:18t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP18\", \"bb1:17t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP19\", \"bb1:16t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP20\", \"bb1:15t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP21\", \"bb1:14t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GND.6\", \"bb1:13t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP22\", \"bb1:12t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:RUN\", \"bb1:11t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP26\", \"bb1:10t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP27\", \"bb1:9t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GND.7\", \"bb1:8t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GP28\", \"bb1:7t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:ADC_VREF\", \"bb1:6t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:3V3\", \"bb1:5t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:3V3_EN\", \"bb1:4t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:GND.8\", \"bb1:3t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:VSYS\", \"bb1:2t.c\", \"\", [ \"$bb\" ] ],\n [ \"pico:VBUS\", \"bb1:1t.c\", \"\", [ \"$bb\" ] ],\n [ \"bz1:1\", \"bb1:25b.f\", \"\", [ \"$bb\" ] ],\n [ \"bz1:2\", \"bb1:26b.f\", \"\", [ \"$bb\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Stepper motor control using Raspberry Pi Pico", + "input": "// Raspberry Pi Pico + Stepper Motor Example\n\n#define DIR_PIN 2\n#define STEP_PIN 3\n\nvoid setup() {\n pinMode(STEP_PIN, OUTPUT);\n pinMode(DIR_PIN, OUTPUT);\n digitalWrite(STEP_PIN, LOW);\n}\n\nvoid loop() {\n // Move 200 steps (one rotation) CW over one second\n digitalWrite(DIR_PIN, HIGH);\n for (int i = 0; i < 200; i++) {\n digitalWrite(STEP_PIN, HIGH);\n digitalWrite(STEP_PIN, LOW);\n delay(5); // 5 ms * 200 = 1 second\n }\n\n delay(500); // Wait half a second\n\n // Move 200 steps (one rotation) CCW over 400 millis\n digitalWrite(DIR_PIN, LOW); \n for (int i = 0; i < 200; i++) {\n digitalWrite(STEP_PIN, HIGH);\n digitalWrite(STEP_PIN, LOW);\n delay(2); // 2 ms * 200 = 0.4 seconds\n }\n\n delay(1000); // Wait another second\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-pi-pico\", \"id\": \"pico\", \"top\": 63.95, \"left\": 86.4, \"attrs\": {} },\n { \"type\": \"wokwi-a4988\", \"id\": \"drv1\", \"top\": 91.4, \"left\": 226, \"rotate\": 270, \"attrs\": {} },\n {\n \"type\": \"wokwi-stepper-motor\",\n \"id\": \"stepper1\",\n \"top\": -179.4,\n \"left\": 141.6,\n \"attrs\": { \"display\": \"angle\" }\n }\n ],\n \"connections\": [\n [ \"drv1:1B\", \"stepper1:B-\", \"black\", [ \"v0\" ] ],\n [ \"drv1:1A\", \"stepper1:B+\", \"green\", [ \"v0\" ] ],\n [ \"stepper1:A+\", \"drv1:2A\", \"blue\", [ \"v0\" ] ],\n [ \"stepper1:A-\", \"drv1:2B\", \"red\", [ \"v0\" ] ],\n [ \"drv1:SLEEP\", \"drv1:RESET\", \"green\", [ \"v15.92\", \"h-9.9\" ] ],\n [ \"drv1:STEP\", \"pico:GP3\", \"orange\", [ \"v130.8\", \"h-203.87\", \"v-163.2\" ] ],\n [ \"drv1:DIR\", \"pico:GP2\", \"violet\", [ \"v140.4\", \"h-223.07\", \"v-182.4\" ] ],\n [ \"drv1:GND.2\", \"pico:GND.8\", \"black\", [ \"v0\" ] ],\n [ \"pico:VBUS\", \"drv1:VDD\", \"red\", [ \"h0\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for Mini piano using raspberry pi pico", + "input": "#include \"pitches.h\"\n\n#define SPEAKER_PIN 8\n\nconst uint8_t buttonPins[] = { 12, 11, 10, 9, 7, 6, 5, 4 };\nconst int buttonTones[] = {\n NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,\n NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5 \n};\nconst int numTones = sizeof(buttonPins) / sizeof(buttonPins[0]);\n\nvoid setup() {\n for (uint8_t i = 0; i < numTones; i++) {\n pinMode(buttonPins[i], INPUT_PULLUP);\n }\n pinMode(SPEAKER_PIN, OUTPUT);\n}\n\nvoid loop() {\n int pitch = 0;\n for (uint8_t i = 0; i < numTones; i++) {\n if (digitalRead(buttonPins[i]) == LOW) {\n pitch = buttonTones[i];\n }\n }\n if (pitch) {\n tone(SPEAKER_PIN, pitch);\n } else {\n noTone(SPEAKER_PIN);\n }\n delay(10);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 183.54,\n \"left\": 67.92,\n \"rotate\": 90,\n \"attrs\": { \"env\": \"arduino-community\" }\n },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"buzzer\",\n \"top\": 208.42,\n \"left\": 382.39,\n \"rotate\": 90,\n \"attrs\": { \"volume\": \"0.2\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": 70,\n \"left\": 0,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"red\", \"key\": \"1\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn2\",\n \"top\": 70,\n \"left\": 50,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"orange\", \"key\": \"2\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn3\",\n \"top\": 70,\n \"left\": 100,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"yellow\", \"key\": \"3\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn4\",\n \"top\": 70,\n \"left\": 150,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"green\", \"key\": \"4\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn5\",\n \"top\": 70,\n \"left\": 200,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"cyan\", \"key\": \"5\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn6\",\n \"top\": 70,\n \"left\": 250,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"blue\", \"key\": \"6\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn7\",\n \"top\": 70,\n \"left\": 300,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"purple\", \"key\": \"7\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn8\",\n \"top\": 70,\n \"left\": 350,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"red\", \"key\": \"8\" }\n }\n ],\n \"connections\": [\n [ \"pico:GND.1\", \"buzzer:1\", \"black\", [ \"v-12\", \"*\", \"h-15\" ] ],\n [ \"pico:GP12\", \"btn1:1.r\", \"red\", [ \"v-8\", \"*\", \"v46\" ] ],\n [ \"pico:GND.1\", \"btn1:2.r\", \"black\", [ \"v-12\", \"*\", \"h6\" ] ],\n [ \"pico:GP11\", \"btn2:1.r\", \"orange\", [ \"v-4\", \"*\", \"v40\" ] ],\n [ \"pico:GND.1\", \"btn2:2.r\", \"black\", [ \"v-12\", \"*\", \"h6\" ] ],\n [ \"pico:GP10\", \"btn3:1.r\", \"yellow\", [ \"v0\", \"*\", \"v28\" ] ],\n [ \"pico:GND.1\", \"btn3:2.r\", \"black\", [ \"v-12\", \"*\", \"h-6\" ] ],\n [ \"pico:GP9\", \"btn4:1.r\", \"green\", [ \"v-36\", \"*\", \"v20\" ] ],\n [ \"pico:GND.1\", \"btn4:2.r\", \"black\", [ \"v-12\", \"*\", \"h-6\" ] ],\n [ \"pico:GP8\", \"buzzer:2\", \"gold\", [ \"v-32\", \"*\", \"h-10\" ] ],\n [ \"pico:GP7\", \"btn5:1.r\", \"cyan\", [ \"v-24\", \"*\", \"h0\" ] ],\n [ \"pico:GND.1\", \"btn5:2.r\", \"black\", [ \"v-12\", \"*\", \"h-15\", \"v4\" ] ],\n [ \"pico:GP6\", \"btn6:1.r\", \"blue\", [ \"v-24\", \"*\", \"h0\" ] ],\n [ \"pico:GND.1\", \"btn6:2.r\", \"black\", [ \"v-12\", \"*\", \"h-10\", \"v4\" ] ],\n [ \"pico:GP5\", \"btn7:1.r\", \"purple\", [ \"v-20\", \"*\", \"h0\" ] ],\n [ \"pico:GND.1\", \"btn7:2.r\", \"black\", [ \"v-12\", \"*\", \"h-8\", \"v4\" ] ],\n [ \"pico:GP4\", \"btn8:1.r\", \"red\", [ \"v-16\", \"*\", \"h0\" ] ],\n [ \"pico:GND.1\", \"btn8:2.r\", \"black\", [ \"v-12\", \"*\", \"h-8\", \"v4\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for 4 digit timer using raspberry pi pico", + "input": "#include \"segment.pio.h\"\n\nuint8_t digits[] = {\n 0b11000000, // 0\n 0b11111001, // 1\n 0b10100100, // 2 \n 0b10110000, // 3\n 0b10011001, // 4\n 0b10010010, // 5\n 0b10000010, // 6\n 0b11111000, // 7\n 0b10000000, // 8\n 0b10011000, // 9\n};\n\nconst uint8_t first_segment_pin = 2;\nconst uint8_t first_digit_pin = 10;\n\nvoid setup() {\n Serial1.begin(115200);\n Serial1.println(\"Raspberry Pi Pico PIO 7-Segment Example\");\n\n // Load the PIO program and initialize the machine\n auto offset = pio_add_program(pio0, &segment_program);\n segment_program_init(pio0, 0, offset, first_segment_pin, first_digit_pin);\n}\n\nvoid displayNumber(uint value) {\n pio_sm_put(pio0, 0, \n digits[value / 1000 % 10] << 24 |\n digits[value / 100 % 10] << 16 |\n digits[value / 10 % 10] << 8 |\n digits[value % 10]\n );\n}\n\nint i = 0;\nvoid loop() {\n displayNumber(i++);\n delay(200);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 65.16,\n \"left\": -27.77,\n \"rotate\": 90,\n \"hide\": false,\n \"attrs\": { \"env\": \"arduino-community\" }\n },\n {\n \"type\": \"wokwi-7segment\",\n \"id\": \"sevseg1\",\n \"top\": -21.97,\n \"left\": -85.69,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"digits\": \"4\" }\n }\n ],\n \"connections\": [\n [ \"pico:GP0\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"pico:GP1\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"sevseg1:A\", \"pico:GP2\", \"green\", [ \"v-21\", \"h145\", \"v115\", \"h-68\" ] ],\n [ \"sevseg1:B\", \"pico:GP3\", \"green\", [ \"v-15\", \"h100\", \"v103\", \"h-65\" ] ],\n [ \"sevseg1:C\", \"pico:GP4\", \"green\", [ \"v16\", \"h37\" ] ],\n [ \"sevseg1:D\", \"pico:GP5\", \"green\", [ \"v22\", \"h53\" ] ],\n [ \"sevseg1:E\", \"pico:GP6\", \"green\", [ \"v32\", \"h42\" ] ],\n [ \"sevseg1:F\", \"pico:GP7\", \"green\", [ \"v-13\", \"h-96\", \"v116\", \"h104\" ] ],\n [ \"sevseg1:G\", \"pico:GP8\", \"green\", [ \"v11\", \"h1\" ] ],\n [ \"sevseg1:DP\", \"pico:GP9\", \"green\", [ \"v7\", \"h-3\" ] ],\n [ \"sevseg1:DIG1\", \"pico:GP10\", \"blue\", [ \"v-19\", \"h-84\", \"v128\", \"h81\" ] ],\n [ \"sevseg1:DIG2\", \"pico:GP11\", \"blue\", [ \"v-28\", \"h-121\", \"v144\", \"h80\" ] ],\n [ \"sevseg1:DIG3\", \"pico:GP12\", \"blue\", [ \"v-39\", \"h-139\", \"v162\", \"h79\" ] ],\n [ \"sevseg1:DIG4\", \"pico:GP13\", \"blue\", [ \"v66\", \"h-82\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for Pico keyboard with LED", + "input": "#include \n\nconst uint8_t LEDS = 12;\nconst uint8_t ROWS = 4;\nconst uint8_t COLS = 4;\n\nchar keys[ROWS][COLS] = {\n { '1', '2', '3', 'A' },\n { '4', '5', '6', 'B' },\n { '7', '8', '9', 'C' },\n { '*', '0', '#', 'D' }\n};\n\n// Pins connected to LED1, LED2, LED3, ...LED12\nuint8_t ledPins[LEDS] = { 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 28, 27 };\nuint8_t rowPins[ROWS] = { 26, 22, 21, 20 }; // Pins connected to R1, R2, R3, R4\nuint8_t colPins[COLS] = { 19, 18, 17, 16 }; // Pins connected to C1, C2, C3, C4\n\nKeypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);\n\nvoid setup() {\n for (uint8_t l = 0; l < LEDS; l++) {\n pinMode(ledPins[l], OUTPUT);\n digitalWrite(ledPins[l], LOW);\n }\n}\n\nvoid loop() {\n char key = keypad.getKey();\n\n if (key != NO_KEY) {\n switch (key) {\n case '1': digitalWrite(ledPins[0], HIGH);\n break;\n case '2': digitalWrite(ledPins[1], HIGH);\n break;\n case '3': digitalWrite(ledPins[2], HIGH);\n break;\n case '4': digitalWrite(ledPins[3], HIGH);\n break;\n case '5': digitalWrite(ledPins[4], HIGH);\n break;\n case '6': digitalWrite(ledPins[5], HIGH);\n break;\n case '7': digitalWrite(ledPins[6], HIGH);\n break;\n case '8': digitalWrite(ledPins[7], HIGH);\n break;\n case '9':\n for (uint8_t l = 0; l < 8; l++) {\n digitalWrite(ledPins[l], HIGH);\n }\n break;\n case '0':\n for (uint8_t l = 0; l < 8; l++) {\n digitalWrite(ledPins[l], LOW);\n }\n break;\n case 'A': digitalWrite(ledPins[8], HIGH);\n break;\n case 'B': digitalWrite(ledPins[9], HIGH);\n break;\n case 'C': digitalWrite(ledPins[10], HIGH);\n break;\n case 'D': digitalWrite(ledPins[11], HIGH);\n break;\n case '*':\n for (uint8_t l = 8; l < 12; l++) {\n digitalWrite(ledPins[l], HIGH);\n }\n break;\n case '#':\n for (uint8_t l = 8; l < 12; l++) {\n digitalWrite(ledPins[l], LOW);\n }\n break;\n }\n }\n\n delay(10);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anderson Costa\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-pi-pico\", \"id\": \"pico\", \"top\": 118, \"left\": 348, \"rotate\": 90, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"rp1\",\n \"top\": 349.55,\n \"left\": 19.2,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"rp2\",\n \"top\": 368.75,\n \"left\": 19.2,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"rp3\",\n \"top\": 426.35,\n \"left\": 19.2,\n \"attrs\": { \"value\": \"1000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"rp4\",\n \"top\": 397.55,\n \"left\": 19.2,\n \"attrs\": { \"value\": \"1000\" }\n },\n { \"type\": \"wokwi-membrane-keypad\", \"id\": \"keypad1\", \"top\": -30.8, \"left\": -13.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": 20,\n \"left\": 420,\n \"attrs\": { \"color\": \"blue\", \"label\": \"8\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 90,\n \"left\": 415,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": 20,\n \"left\": 400,\n \"attrs\": { \"color\": \"blue\", \"label\": \"7\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 90,\n \"left\": 395,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": 20,\n \"left\": 380,\n \"attrs\": { \"color\": \"blue\", \"label\": \"6\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 90,\n \"left\": 375,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led4\",\n \"top\": 20,\n \"left\": 360,\n \"attrs\": { \"color\": \"blue\", \"label\": \"5\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r4\",\n \"top\": 90,\n \"left\": 355,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led5\",\n \"top\": 20,\n \"left\": 340,\n \"attrs\": { \"color\": \"blue\", \"label\": \"4\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r5\",\n \"top\": 90,\n \"left\": 335,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led6\",\n \"top\": 20,\n \"left\": 320,\n \"attrs\": { \"color\": \"blue\", \"label\": \"3\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r6\",\n \"top\": 90,\n \"left\": 315,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led7\",\n \"top\": 20,\n \"left\": 300,\n \"attrs\": { \"color\": \"blue\", \"label\": \"2\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r7\",\n \"top\": 90,\n \"left\": 295,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led8\",\n \"top\": 20,\n \"left\": 280,\n \"attrs\": { \"color\": \"blue\", \"label\": \"1\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r8\",\n \"top\": 90,\n \"left\": 275,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led9\",\n \"top\": 20,\n \"left\": 440,\n \"attrs\": { \"color\": \"red\", \"label\": \"A\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r9\",\n \"top\": 90,\n \"left\": 435,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led10\",\n \"top\": 20,\n \"left\": 460,\n \"attrs\": { \"color\": \"red\", \"label\": \"B\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r10\",\n \"top\": 90,\n \"left\": 455,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led11\",\n \"top\": 20,\n \"left\": 480,\n \"attrs\": { \"color\": \"red\", \"label\": \"C\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r11\",\n \"top\": 90,\n \"left\": 475,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led12\",\n \"top\": 20,\n \"left\": 500,\n \"attrs\": { \"color\": \"red\", \"label\": \"D\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r12\",\n \"top\": 90,\n \"left\": 495,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n }\n ],\n \"connections\": [\n [ \"pico:GP0\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"pico:GP1\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"keypad1:C4\", \"pico:GP16\", \"green\", [ \"v15\", \"h132\" ] ],\n [ \"keypad1:C3\", \"pico:GP17\", \"green\", [ \"v25\", \"h182\" ] ],\n [ \"keypad1:C2\", \"pico:GP18\", \"green\", [ \"v35\", \"h204\" ] ],\n [ \"keypad1:C1\", \"pico:GP19\", \"green\", [ \"v45\", \"h222\" ] ],\n [ \"keypad1:R4\", \"pico:GP20\", \"green\", [ \"v55\", \"h240\" ] ],\n [ \"keypad1:R3\", \"pico:GP21\", \"green\", [ \"v65\", \"h260\" ] ],\n [ \"keypad1:R2\", \"pico:GP22\", \"green\", [ \"v75\", \"h286\" ] ],\n [ \"keypad1:R1\", \"pico:GP26\", \"green\", [ \"v85\", \"h299\" ] ],\n [ \"r1:1\", \"led1:A\", \"green\", [ \"h0\" ] ],\n [ \"r2:1\", \"led2:A\", \"green\", [ \"h0\" ] ],\n [ \"r3:1\", \"led3:A\", \"green\", [ \"h0\" ] ],\n [ \"r4:1\", \"led4:A\", \"green\", [ \"h0\" ] ],\n [ \"r5:1\", \"led5:A\", \"green\", [ \"h0\" ] ],\n [ \"r6:1\", \"led6:A\", \"green\", [ \"h0\" ] ],\n [ \"r7:1\", \"led7:A\", \"green\", [ \"h0\" ] ],\n [ \"r8:1\", \"led8:A\", \"green\", [ \"h0\" ] ],\n [ \"pico:GND.4\", \"led8:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led7:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led6:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led5:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led4:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led3:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led2:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led1:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led9:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led10:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led11:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GND.4\", \"led12:C\", \"black\", [ \"v-25\", \"h-22\", \"v-77\", \"h6\" ] ],\n [ \"pico:GP4\", \"r1:2\", \"green\", [ \"v-28\", \"h10\", \"v-20\" ] ],\n [ \"pico:GP5\", \"r2:2\", \"green\", [ \"v-36\", \"h8\" ] ],\n [ \"pico:GP6\", \"r3:2\", \"green\", [ \"v-26\", \"h7\" ] ],\n [ \"pico:GP7\", \"r4:2\", \"green\", [ \"v-36\", \"h-3\" ] ],\n [ \"pico:GP8\", \"r5:2\", \"green\", [ \"v-33\", \"h-13\" ] ],\n [ \"pico:GP9\", \"r6:2\", \"green\", [ \"v-23\", \"h-14\", \"v-11\", \"h-10\" ] ],\n [ \"pico:GP10\", \"r7:2\", \"green\", [ \"v-22\", \"h-16\", \"v-9\" ] ],\n [ \"pico:GP11\", \"r8:2\", \"green\", [ \"v-12\", \"h-17\", \"v-24\", \"h-18\" ] ],\n [ \"r9:1\", \"led9:A\", \"green\", [ \"h0\" ] ],\n [ \"r10:1\", \"led10:A\", \"green\", [ \"h0\" ] ],\n [ \"r11:1\", \"led11:A\", \"green\", [ \"h0\" ] ],\n [ \"r12:1\", \"led12:A\", \"green\", [ \"h0\" ] ],\n [ \"pico:GP3\", \"r9:2\", \"green\", [ \"v-20\", \"h10\", \"v-20\", \"h20\", \"v-13\" ] ],\n [ \"pico:GP2\", \"r10:2\", \"green\", [ \"v-15\", \"h20\", \"v-15\", \"h20\", \"v-22\" ] ],\n [ \"pico:GP27\", \"r12:2\", \"green\", [ \"v165\", \"h152\" ] ],\n [ \"pico:GP28\", \"r11:2\", \"green\", [ \"v155\", \"h104\" ] ],\n [ \"rp1:2\", \"keypad1:R1\", \"green\", [ \"h8.4\", \"v-48\" ] ],\n [ \"rp2:2\", \"keypad1:R2\", \"green\", [ \"h18\", \"v-67.2\" ] ],\n [ \"rp4:2\", \"keypad1:R3\", \"green\", [ \"h27.6\", \"v-96\" ] ],\n [ \"rp3:2\", \"keypad1:R4\", \"green\", [ \"h37.2\", \"v-124.8\" ] ],\n [ \"rp1:1\", \"rp2:1\", \"red\", [ \"v0\" ] ],\n [ \"rp2:1\", \"rp4:1\", \"red\", [ \"v0\" ] ],\n [ \"rp4:1\", \"rp3:1\", \"red\", [ \"v0\" ] ],\n [ \"rp3:1\", \"pico:3V3\", \"red\", [ \"v19.2\", \"h417.15\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for LED blink using raspberry pi pico", + "input": "from machine import Pin\nfrom utime import sleep\n\nprint(\"Hello, Pi Pico!\")\n\nled = Pin(5, Pin.OUT)\nwhile True:\n led.toggle()\n sleep(0.5)", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 0,\n \"left\": 0,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": -2.67,\n \"left\": -65.33,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"color\": \"red\" }\n }\n ],\n \"connections\": [\n [ \"pico:GP0\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"pico:GP1\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"pico:GP5\", \"led1:A\", \"green\", [ \"h0\" ] ],\n [ \"pico:GND.2\", \"led1:C\", \"black\", [ \"h0\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for 7 segment diaplay using raspberry pi pico", + "input": "#include \n#include \"pico/stdlib.h\"\n#include \"hardware/gpio.h\"\n\n/*\n Our 7 Segment display has pins as follows:\n\n --A--\n F B\n --G--\n E C\n --D--\n\n By default we are allocating GPIO 2 to segment A, 3 to B etc.\n So, connect GPIO 2 to pin A on the 7 segment LED display etc. Don't forget\n the appropriate resistors, best to use one for each segment!\n\n Connect button so that pressing the switch connects the GPIO 9 (default) to\n ground (pull down)\n*/\n\n#define FIRST_GPIO 2\n#define BUTTON_GPIO (FIRST_GPIO+7)\n\n// This array converts a number 0-9 to a bit pattern to send to the GPIOs\nint bits[10] = {\n 0x3f, // 0\n 0x06, // 1\n 0x5b, // 2\n 0x4f, // 3\n 0x66, // 4\n 0x6d, // 5\n 0x7d, // 6\n 0x07, // 7\n 0x7f, // 8\n 0x67 // 9\n};\n\n/// \\tag::hello_gpio[]\nint main() {\n stdio_init_all();\n printf(\"Hello, 7segment - press button to count down!\\n\");\n\n // We could use gpio_set_dir_out_masked() here\n for (int gpio = FIRST_GPIO; gpio < FIRST_GPIO + 7; gpio++) {\n gpio_init(gpio);\n gpio_set_dir(gpio, GPIO_OUT);\n // Our bitmap above has a bit set where we need an LED on, BUT, we are pulling low to light\n // so invert our output\n gpio_set_outover(gpio, GPIO_OVERRIDE_INVERT);\n }\n\n gpio_init(BUTTON_GPIO);\n gpio_set_dir(BUTTON_GPIO, GPIO_IN);\n // We are using the button to pull down to 0v when pressed, so ensure that when\n // unpressed, it uses internal pull ups. Otherwise when unpressed, the input will\n // be floating.\n gpio_pull_up(BUTTON_GPIO);\n\n int val = 0;\n while (true) {\n // Count upwards or downwards depending on button input\n // We are pulling down on switch active, so invert the get to make\n // a press count downwards\n if (!gpio_get(BUTTON_GPIO)) {\n if (val == 9) {\n val = 0;\n } else {\n val++;\n }\n } else if (val == 0) {\n val = 9;\n } else {\n val--;\n }\n\n // We are starting with GPIO 2, our bitmap starts at bit 0 so shift to start at 2.\n int32_t mask = bits[val] << FIRST_GPIO;\n\n // Set all our GPIOs in one go!\n // If something else is using GPIO, we might want to use gpio_put_masked()\n gpio_set_mask(mask);\n sleep_ms(250);\n gpio_clr_mask(mask);\n }\n}\n/// \\end::hello_gpio[]", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 67.9,\n \"left\": 132.45,\n \"rotate\": 90,\n \"attrs\": { \"builder\": \"pico-sdk\" }\n },\n {\n \"type\": \"wokwi-7segment\",\n \"id\": \"sevseg1\",\n \"top\": 14.58,\n \"left\": 158.68,\n \"attrs\": { \"common\": \"anode\" }\n },\n { \"type\": \"wokwi-slide-switch\", \"id\": \"sw1\", \"top\": 62, \"left\": 99.1, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"pico:GP0\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"pico:GP2\", \"sevseg1:A\", \"green\", [ \"v-135\", \"h-40\" ] ],\n [ \"pico:GP3\", \"sevseg1:B\", \"green\", [ \"v-128\", \"h-21\" ] ],\n [ \"pico:GP4\", \"sevseg1:C\", \"green\", [ \"v-33\", \"h-21\" ] ],\n [ \"pico:GP5\", \"sevseg1:D\", \"green\", [ \"v-28\", \"h-2\" ] ],\n [ \"pico:GP6\", \"sevseg1:E\", \"green\", [ \"v-18\", \"h-20\" ] ],\n [ \"pico:GP7\", \"sevseg1:F\", \"green\", [ \"v-14\", \"h-22\", \"v-108\", \"h21\" ] ],\n [ \"pico:GP8\", \"sevseg1:G\", \"green\", [ \"v-10\", \"h-17\", \"v-123\", \"h14\" ] ],\n [ \"pico:GP9\", \"sw1:3\", \"blue\", [ \"v-6\", \"h-17\", \"v-29\" ] ],\n [ \"sw1:2\", \"pico:GND.4\", \"black\", [ \"v12\", \"h-18\" ] ],\n [ \"pico:VSYS\", \"sevseg1:COM.2\", \"red\", [ \"v8\", \"h37\", \"v-242\", \"h-5\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for neopixel ring using Pi pico", + "input": "import time\nfrom neopixel import Neopixel\npixels = Neopixel(17, 0, 6, \"GRB\")\n\ncolors = [\n (0xb6, 0xe4, 0x30),\n (0x42, 0xd1, 0xe0),\n]\n\npixel_index = 0\ncolor_index = 0\nwhile True:\n pixels.set_pixel(pixel_index, colors[color_index])\n pixels.show()\n #print(pixel_index, colors[color_index])\n pixel_index += 1\n if pixel_index == 16:\n pixel_index = 0\n color_index = (color_index + 1) % 2\n time.sleep(0.1)", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 80.37,\n \"left\": 2.96,\n \"attrs\": { \"env\": \"micropython-20210902-v1.17\" }\n },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring1\",\n \"top\": 3.2,\n \"left\": -177.15,\n \"attrs\": { \"pixels\": \"16\" }\n }\n ],\n \"connections\": [\n [ \"pico:GP6\", \"ring1:DIN\", \"green\", [ \"h0\" ] ],\n [ \"ring1:VCC\", \"pico:3V3\", \"red\", [ \"v128.24\", \"h238.19\", \"v-147.43\" ] ],\n [ \"ring1:GND\", \"pico:GND.3\", \"black\", [ \"v0\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for SSD1306 timer with micropython", + "input": "from machine import Pin, I2C\nfrom ssd1306 import SSD1306_I2C\nimport framebuf, sys\nimport utime\n\npix_res_x = 128\npix_res_y = 64\n\ndef init_i2c(scl_pin, sda_pin):\n # Initialize I2C device\n i2c_dev = I2C(1, scl=Pin(scl_pin), sda=Pin(sda_pin), freq=200000)\n i2c_addr = [hex(ii) for ii in i2c_dev.scan()]\n \n if not i2c_addr:\n print('No I2C Display Found')\n sys.exit()\n else:\n print(\"I2C Address : {}\".format(i2c_addr[0]))\n print(\"I2C Configuration: {}\".format(i2c_dev))\n \n return i2c_dev\n\ndef display_logo(oled):\n # Display the Raspberry Pi logo on the OLED\n buffer = bytearray(b\"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00|?\\x00\\x01\\x86@\\x80\\x01\\x01\\x80\\x80\\x01\\x11\\x88\\x80\\x01\\x05\\xa0\\x80\\x00\\x83\\xc1\\x00\\x00C\\xe3\\x00\\x00~\\xfc\\x00\\x00L'\\x00\\x00\\x9c\\x11\\x00\\x00\\xbf\\xfd\\x00\\x00\\xe1\\x87\\x00\\x01\\xc1\\x83\\x80\\x02A\\x82@\\x02A\\x82@\\x02\\xc1\\xc2@\\x02\\xf6>\\xc0\\x01\\xfc=\\x80\\x01\\x18\\x18\\x80\\x01\\x88\\x10\\x80\\x00\\x8c!\\x00\\x00\\x87\\xf1\\x00\\x00\\x7f\\xf6\\x00\\x008\\x1c\\x00\\x00\\x0c \\x00\\x00\\x03\\xc0\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\")\n fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)\n \n oled.fill(0)\n oled.blit(fb, 96, 0)\n oled.show()\n\ndef display_text(oled):\n # Display text on the OLED\n oled.text(\"Raspberry Pi\", 5, 5)\n oled.text(\"Pico\", 5, 15)\n oled.show()\n\ndef display_anima(oled):\n # Display a simple timer animation on the OLED\n start_time = utime.ticks_ms()\n\n while True:\n elapsed_time = (utime.ticks_diff(utime.ticks_ms(), start_time) // 1000) + 1\n \n # Clear the specific line by drawing a filled black rectangle\n oled.fill_rect(5, 40, oled.width - 5, 8, 0)\n\n oled.text(\"Timer:\", 5, 30)\n oled.text(str(elapsed_time) + \" sec\", 5, 40)\n oled.show()\n utime.sleep_ms(1000)\n\ndef main():\n i2c_dev = init_i2c(scl_pin=27, sda_pin=26)\n oled = SSD1306_I2C(pix_res_x, pix_res_y, i2c_dev)\n display_logo(oled)\n display_text(oled)\n display_anima(oled)\n\nif __name__ == '__main__':\n main()", + "output": "{\n \"version\": 1,\n \"author\": \"Anderson Costa\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-mini\", \"id\": \"bb1\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 112,\n \"left\": 50,\n \"rotate\": 270,\n \"attrs\": { \"env\": \"micropython-20220618-v1.19.1\" }\n },\n { \"type\": \"board-ssd1306\", \"id\": \"oled1\", \"top\": 60, \"left\": 80, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"bb1:2b.f\", \"bb1:2t.e\", \"black\", [ \"v0\" ] ],\n [ \"bb1:3b.f\", \"bb1:3t.e\", \"red\", [ \"v0\" ] ],\n [ \"bb1:4b.f\", \"bb1:4t.e\", \"purple\", [ \"v0\" ] ],\n [ \"bb1:5b.f\", \"bb1:5t.e\", \"orange\", [ \"v0\" ] ],\n [ \"bb1:2t.d\", \"bb1:12t.d\", \"black\", [ \"v0\" ] ],\n [ \"bb1:3t.c\", \"bb1:13t.c\", \"red\", [ \"v0\" ] ],\n [ \"bb1:4t.b\", \"bb1:14t.b\", \"purple\", [ \"v0\" ] ],\n [ \"bb1:5t.a\", \"bb1:15t.a\", \"orange\", [ \"v0\" ] ],\n [ \"bb1:12t.e\", \"oled1:GND\", \"black\", [ \"v0\" ] ],\n [ \"bb1:13t.e\", \"oled1:VCC\", \"red\", [ \"v0\" ] ],\n [ \"bb1:14t.e\", \"oled1:SCL\", \"purple\", [ \"v0\" ] ],\n [ \"bb1:15t.e\", \"oled1:SDA\", \"orange\", [ \"v0\" ] ],\n [ \"pico:9\", \"bb1:4b.j\", \"purple\", [ \"v0\" ] ],\n [ \"pico:8\", \"bb1:5b.j\", \"orange\", [ \"v0\" ] ],\n [ \"bb1:2t.a\", \"bb1:17t.a\", \"black\", [ \"v-7.93\", \"h144\" ] ],\n [ \"bb1:15t.d\", \"bb1:16t.d\", \"orange\", [ \"v0\" ] ],\n [ \"pico:3V3_EN\", \"bb1:3b.j\", \"red\", [ \"v0\" ] ],\n [ \"pico:GND.8\", \"bb1:2b.j\", \"black\", [ \"v0\" ] ],\n [ \"pico:GP27\", \"bb1:4b.j\", \"purple\", [ \"v-15\", \"h-38.25\" ] ],\n [ \"pico:GP26\", \"bb1:5b.j\", \"orange\", [ \"v-25\", \"h-36.92\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for servo control based on temperture using Pico", + "input": "from machine import Pin, I2C, ADC, PWM\nimport time\nfrom ssd1306 import SSD1306_I2C\nimport dht\n\n# LED Configuration\nLED_PIN = 25 # Built-in LED for Raspberry Pi Pico\nled = Pin(LED_PIN, Pin.OUT)\n\n# LDR Configuration\nLDR_PIN = 26 # ADC pin for LDR\nldr = ADC(LDR_PIN) \nLDR_THRESHOLD = 30 # Simulated light level threshold at 30\n\n# DHT Sensor Configuration\nDHT_PIN = 0 # GPIO pin connected to DHT22\ndht_sensor = dht.DHT22(Pin(DHT_PIN))\n\n# Shared variables for temperature and humidity\ntemperature = None\nhumidity = None\nlast_temperature = None # Track last temperature\nservo_swept = False # Flag to indicate if the servo has swept\n\n# OLED Display Configuration\nWIDTH = 128 # Display width\nHEIGHT = 64 # Display height\ni2c = I2C(0, scl=Pin(17), sda=Pin(16), freq=400000) # I2C configuration\ndisplay = SSD1306_I2C(WIDTH, HEIGHT, i2c) # Initialize OLED display\n\n# PIR Sensor Configuration\nPIR_PIN = 2\npir = Pin(PIR_PIN, Pin.IN)\n\n# Servo motor configuration\nSERVO_PIN = 20 # GPIO pin connected to the servo's PWM signal\nservo = PWM(Pin(SERVO_PIN))\nservo.freq(50) # Set PWM frequency to 50Hz (standard for servos)\n\ndef set_servo_angle(angle):\n \"\"\"Moves the servo to the specified angle.\"\"\"\n if 0 <= angle <= 360:\n # Convert angle (0-360) to duty cycle (1000-9000 for 1ms to 2ms pulse)\n duty = int(1000 + (angle / 360) * 8000)\n servo.duty_u16(duty)\n \n\ndef read_ldr():\n \"\"\"Reads the LDR value from the ADC pin.\"\"\"\n return ldr.read_u16()\n\ndef read_sensor_data():\n \"\"\"Reads temperature and humidity from the DHT sensor.\"\"\"\n global temperature, humidity\n try:\n dht_sensor.measure()\n temperature = dht_sensor.temperature()\n humidity = dht_sensor.humidity()\n except OSError as e:\n print(f\"Failed to read from DHT sensor: {e}\")\n temperature = None\n humidity = None\n\ndef update_display(temp, hum, ldr_value, pir):\n \"\"\"Updates the OLED display with temperature, Lux, and humidity data.\"\"\"\n display.fill(0) # Clear the display\n display.text(\"Sensor Readings:\", 0, 0)\n\n # Display temperature and humidity\n if temp is not None and hum is not None:\n display.text(f\"Temp: {temp:.2f}C\", 0, 16)\n display.text(f\"Humidity: {hum:.2f}%\", 0, 32)\n else:\n display.text(\"Sensor Error!\", 0, 16)\n\n # Display PIR status\n if pir.value() == 0:\n display.text(\"No intruders\", 0, 48)\n else:\n display.text(\"Intruders detected\", 0, 48)\n\n # Display LDR value\n display.text(f\"LDR: {ldr_value}\", 0, 56)\n\n # Render the updated display\n display.show()\n\nwhile True:\n read_sensor_data() # Read data from DHT22\n ldr_value = read_ldr() # Read LDR value\n update_display(temperature, humidity, ldr_value, pir) # Update the OLED display\n time.sleep(2) # Wait before the next reading\n\n # LDR Control\n new = (381445 / ldr_value)\n if new < LDR_THRESHOLD: # Low light condition\n led.value(1) # Turn LED ON\n else: # Bright light condition\n led.value(0) # Turn LED OFF \n\n # PIR Sensor (Motion)\n if pir.value() == 0: # No motion detected\n time.sleep(0.5) \n else: # Motion detected\n time.sleep(0.5) \n\n # Servo Control based on temperature\n if temperature != last_temperature: # Check if temperature has changed\n last_temperature = temperature # Update last temperature\n servo_swept = False # Reset the sweep flag\n\n if not servo_swept: # Only move servo if it hasn't swept\n if temperature >= 30:\n for angle in range(0, 361, 10): # Sweep from 0\u00b0 to 360\u00b0\n set_servo_angle(angle)\n time.sleep(0.1) \n servo_swept = True # Set flag to indicate sweeping is done\n else:\n for angle in range(360, -1, -10): # Sweep from 360\u00b0 to 0\u00b0\n set_servo_angle(angle)\n time.sleep(0.1) \n servo_swept = True # Set flag to indicate sweeping is done", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 25.65,\n \"left\": 3.6,\n \"attrs\": { \"env\": \"micropython-20231227-v1.22.0\" }\n },\n {\n \"type\": \"wokwi-dht22\",\n \"id\": \"dht1\",\n \"top\": -86.1,\n \"left\": -91.8,\n \"attrs\": { \"temperature\": \"-40\", \"humidity\": \"80.5\" }\n },\n {\n \"type\": \"board-ssd1306\",\n \"id\": \"oled1\",\n \"top\": 118.34,\n \"left\": 345.83,\n \"attrs\": { \"i2cAddress\": \"0x3c\" }\n },\n {\n \"type\": \"wokwi-photoresistor-sensor\",\n \"id\": \"ldr1\",\n \"top\": -131.2,\n \"left\": -28,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-pir-motion-sensor\", \"id\": \"pir1\", \"top\": -44, \"left\": -208.98, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": -3.6,\n \"left\": -274.6,\n \"attrs\": { \"color\": \"red\" }\n },\n { \"type\": \"wokwi-servo\", \"id\": \"servo1\", \"top\": -126.8, \"left\": 268.8, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"dht1:VCC\", \"pico:3V3\", \"red\", [ \"v0\" ] ],\n [ \"dht1:SDA\", \"pico:GP0\", \"green\", [ \"v0\" ] ],\n [ \"dht1:GND\", \"pico:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"oled1:VCC\", \"pico:3V3\", \"red\", [ \"v0\" ] ],\n [ \"oled1:SCL\", \"pico:GP17\", \"magenta\", [ \"v-57.6\", \"h-210.9\", \"v144\" ] ],\n [ \"oled1:SDA\", \"pico:GP16\", \"green\", [ \"v-28.8\", \"h-211.13\", \"v124.8\" ] ],\n [ \"oled1:GND\", \"pico:GND.6\", \"black\", [ \"v-38.4\", \"h-201.6\", \"v67.2\" ] ],\n [ \"ldr1:VCC\", \"pico:3V3\", \"red\", [ \"h28.8\", \"v163.2\" ] ],\n [ \"pico:GP15\", \"ldr1:DO\", \"yellow\", [ \"v9.6\", \"h144\", \"v-325.8\" ] ],\n [ \"pico:GP26\", \"ldr1:AO\", \"green\", [ \"h68.4\", \"v-210.5\" ] ],\n [ \"ldr1:GND\", \"pico:GND.6\", \"black\", [ \"h19.2\", \"v249.2\", \"h-87.6\" ] ],\n [ \"pir1:VCC\", \"pico:3V3\", \"red\", [ \"v0\" ] ],\n [ \"pir1:GND\", \"pico:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"pir1:OUT\", \"pico:GP2\", \"green\", [ \"v0\" ] ],\n [ \"led1:C\", \"pico:GND.1\", \"black\", [ \"v19.2\", \"h269.2\" ] ],\n [ \"led1:A\", \"pico:GP4\", \"green\", [ \"v0\" ] ],\n [ \"servo1:GND\", \"pico:GND.8\", \"black\", [ \"h-76.8\", \"v115.2\" ] ],\n [ \"servo1:V+\", \"pico:3V3\", \"red\", [ \"h-67.2\", \"v124.9\" ] ],\n [ \"servo1:PWM\", \"pico:GP20\", \"cyan\", [ \"h-57.6\", \"v211.4\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for keyboard input using pi pico", + "input": "import rp2\nfrom rp2 import PIO\nfrom machine import Pin\nfrom time import sleep\n# ------ #\n# sevseg #\n# ------ #\n\n@rp2.asm_pio(set_init=[PIO.IN_HIGH]*4)\ndef keypad():\n wrap_target()\n set(y, 0) # 0\n label(\"1\")\n mov(isr, null) # 1\n set(pindirs, 1) # 2\n in_(pins, 4) # 3\n set(pindirs, 2) # 4\n in_(pins, 4) # 5\n set(pindirs, 4) # 6\n in_(pins, 4) # 7\n set(pindirs, 8) # 8\n in_(pins, 4) # 9\n mov(x, isr) # 10\n jmp(x_not_y, \"13\") # 11\n jmp(\"1\") # 12\n label(\"13\")\n push(block) # 13\n irq(0)\n mov(y, x) # 14\n jmp(\"1\") # 15\n wrap()\n\nfor i in range(10, 14):\n Pin(i, Pin.IN, Pin.PULL_DOWN)\n\nkey_names = \"*7410852#963DCBA\"\n\ndef oninput(machine):\n keys = machine.get()\n while machine.rx_fifo():\n keys = machine.get()\n pressed = []\n for i in range(len(key_names)):\n if (keys & (1 << i)):\n pressed.append(key_names[i])\n print(\"Keys changed! pressed keys:\", pressed)\n \nsm = rp2.StateMachine(0, keypad, freq=2000, in_base=Pin(10, Pin.IN, Pin.PULL_DOWN), set_base=Pin(6))\nsm.active(1)\nsm.irq(oninput)\n\nprint(\"Please press any key on the keypad, or press Ctrl+C to enter REPL.\")\nwhile True:\n sleep(0.1)", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": 200.57,\n \"left\": -42.52,\n \"rotate\": 90,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-membrane-keypad\",\n \"id\": \"keypad1\",\n \"top\": -126.8,\n \"left\": -157.6,\n \"attrs\": {}\n }\n ],\n \"connections\": [\n [ \"pico:GP6\", \"keypad1:C4\", \"blue\", [ \"v-8\", \"h0\" ] ],\n [ \"pico:GP7\", \"keypad1:C3\", \"blue\", [ \"v-12\", \"h0\" ] ],\n [ \"pico:GP8\", \"keypad1:C2\", \"blue\", [ \"v-16\", \"h0\" ] ],\n [ \"pico:GP9\", \"keypad1:C1\", \"blue\", [ \"v-20\", \"h0\" ] ],\n [ \"pico:GP10\", \"keypad1:R4\", \"purple\", [ \"v-24\", \"h0\" ] ],\n [ \"pico:GP11\", \"keypad1:R3\", \"purple\", [ \"v-28\", \"h0\" ] ],\n [ \"pico:GP12\", \"keypad1:R2\", \"purple\", [ \"v-32\", \"h0\" ] ],\n [ \"pico:GP13\", \"keypad1:R1\", \"purple\", [ \"v-36\", \"h0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for LCD diplay with IR remote", + "input": "#include \n#include \n\n#define PIN_RECEIVER 2 // Signal Pin of IR receiver\n\nIRrecv receiver(PIN_RECEIVER);\n\nLiquidCrystal lcd(12, 11, 10, 9, 8, 7);\n\nvoid setup()\n{\n lcd.begin(16, 2);\n lcd.print(\"\");\n receiver.enableIRIn(); // Start the receiver\n}\n\nvoid loop()\n{\n // Checks received an IR signal\n if (receiver.decode()) {\n translateIR();\n receiver.resume(); // Receive the next value\n }\n}\n\nvoid lcdPrint(char* text)\n{\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.print(\"button pressed:\");\n lcd.setCursor(0, 1);\n lcd.print(text);\n lcd.print(\" code: \");\n lcd.print(receiver.decodedIRData.command);\n}\n\nvoid translateIR()\n{\n // Takes command based on IR code received\n switch (receiver.decodedIRData.command) {\n case 162:\n lcdPrint(\"POWER\");\n break;\n case 226:\n lcdPrint(\"MENU\");\n break;\n case 34:\n lcdPrint(\"TEST\");\n break;\n case 2:\n lcdPrint(\"PLUS\");\n break;\n case 194:\n lcdPrint(\"BACK\");\n break;\n case 224:\n lcdPrint(\"PREV.\");\n break;\n case 168:\n lcdPrint(\"PLAY\");\n break;\n case 144:\n lcdPrint(\"NEXT\");\n break;\n case 104:\n lcdPrint(\"num: 0\");\n break;\n case 152:\n lcdPrint(\"MINUS\");\n break;\n case 176:\n lcdPrint(\"key: C\");\n break;\n case 48:\n lcdPrint(\"num: 1\");\n break;\n case 24:\n lcdPrint(\"num: 2\");\n break;\n case 122:\n lcdPrint(\"num: 3\");\n break;\n case 16:\n lcdPrint(\"num: 4\");\n break;\n case 56:\n lcdPrint(\"num: 5\");\n break;\n case 90:\n lcdPrint(\"num: 6\");\n break;\n case 66:\n lcdPrint(\"num: 7\");\n break;\n case 74:\n lcdPrint(\"num: 8\");\n break;\n case 82:\n lcdPrint(\"num: 9\");\n break;\n default:\n lcd.clear();\n lcd.print(receiver.decodedIRData.command);\n lcd.print(\" other button\");\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anderson Costa\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-arduino-nano\",\n \"id\": \"nano\",\n \"top\": 210,\n \"left\": 245,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-lcd1602\",\n \"id\": \"lcd\",\n \"top\": 25,\n \"left\": 235,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 160,\n \"left\": 450,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-ir-receiver\",\n \"id\": \"ir\",\n \"top\": 185,\n \"left\": 450,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-ir-remote\",\n \"id\": \"remote1\",\n \"top\": 20,\n \"left\": 70,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": {}\n }\n ],\n \"connections\": [\n [ \"nano:GND.2\", \"ds1307:GND\", \"black\", [ \"v20\", \"*\", \"v0\" ] ],\n [ \"nano:5V\", \"ds1307:5V\", \"red\", [ \"v8\", \"*\", \"h-25\", \"v0\" ] ],\n [ \"nano:GND.1\", \"lcd:VSS\", \"black\", [ \"v12\", \"*\", \"h-30\", \"v18\" ] ],\n [ \"nano:GND.1\", \"lcd:K\", \"black\", [ \"v12\", \"*\", \"h-174\", \"v18\" ] ],\n [ \"nano:GND.1\", \"lcd:RW\", \"black\", [ \"v12\", \"*\", \"h-68\", \"v18\" ] ],\n [ \"nano:5V\", \"lcd:VDD\", \"red\", [ \"v8\", \"*\", \"h-35\", \"v22\" ] ],\n [ \"nano:5V\", \"r1:2\", \"red\", [ \"v8\", \"h166\", \"v-112\", \"h50\" ] ],\n [ \"nano:12\", \"lcd:RS\", \"orange\", [ \"v-32\", \"*\", \"h0\", \"v20\" ] ],\n [ \"nano:11\", \"lcd:E\", \"purple\", [ \"v-28\", \"*\", \"h0\", \"v20\" ] ],\n [ \"nano:10\", \"lcd:D4\", \"green\", [ \"v-24\", \"*\", \"h0\", \"v20\" ] ],\n [ \"nano:9\", \"lcd:D5\", \"brown\", [ \"v-20\", \"*\", \"h0\", \"v20\" ] ],\n [ \"nano:8\", \"lcd:D6\", \"gold\", [ \"v-16\", \"*\", \"h0\", \"v20\" ] ],\n [ \"nano:7\", \"lcd:D7\", \"gray\", [ \"v-12\", \"*\", \"h0\", \"v20\" ] ],\n [ \"nano:A4\", \"ds1307:SDA\", \"orange\", [ \"v16\", \"*\", \"h-20\" ] ],\n [ \"nano:A5\", \"ds1307:SCL\", \"purple\", [ \"v20\", \"*\", \"h-15\" ] ],\n [ \"r1:1\", \"lcd:A\", \"red\", [] ],\n [ \"nano:GND.1\", \"ir:GND\", \"black\", [ \"v12\", \"h0\" ] ],\n [ \"nano:5V\", \"ir:VCC\", \"red\", [ \"v0\", \"h0\", \"v8\", \"h0\" ] ],\n [ \"nano:2\", \"ir:DAT\", \"green\", [ \"v-8\", \"h84\", \"v-26\", \"h72\", \"v92\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for Motion detection using PIR sensor and arduino uno", + "input": "/*\n PIR sensor tester\n*/\n\nint ledPin = 13; // choose the pin for the LED\nint inputPin = 2; // choose the input pin (for PIR sensor)\nint pirState = LOW; // we start, assuming no motion detected\nint val = 0; // variable for reading the pin status\n\nvoid setup() {\n pinMode(ledPin, OUTPUT); // declare LED as output\n pinMode(inputPin, INPUT); // declare sensor as input\n\n Serial.begin(9600);\n}\n\nvoid loop() {\n val = digitalRead(inputPin); // read input value\n if (val == HIGH) { // check if the input is HIGH\n digitalWrite(ledPin, HIGH); // turn LED ON\n if (pirState == LOW) {\n // we have just turned on\n Serial.println(\"Motion detected!\");\n // We only want to print on the output change, not state\n pirState = HIGH;\n }\n } else {\n digitalWrite(ledPin, LOW); // turn LED OFF\n if (pirState == HIGH) {\n // we have just turned of\n Serial.println(\"Motion ended!\");\n // We only want to print on the output change, not state\n pirState = LOW;\n }\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-arduino-uno\",\n \"id\": \"uno\",\n \"top\": 98.67,\n \"left\": -98.67,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-pir-motion-sensor\",\n \"id\": \"pir1\",\n \"top\": -42,\n \"left\": 25.81,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": -9,\n \"left\": -32.67,\n \"attrs\": { \"color\": \"red\" }\n }\n ],\n \"connections\": [\n [ \"pir1:VCC\", \"uno:5V\", \"red\", [ \"v19\", \"h-175\", \"v261\", \"h181\" ] ],\n [ \"pir1:OUT\", \"uno:2\", \"green\", [ \"v37\", \"h68\" ] ],\n [ \"uno:13\", \"led1:A\", \"green\", [ \"v-62\", \"h-47\" ] ],\n [ \"uno:GND.1\", \"led1:C\", \"black\", [ \"v-54\", \"h-33\" ] ],\n [ \"pir1:GND\", \"uno:GND.1\", \"black\", [ \"v31\", \"*\", \"v-28\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for potentiometer value plotter", + "input": "void setup() {\n Serial.begin(115200);\n pinMode(A0, INPUT);\n}\n\nvoid loop() {\n int value = analogRead(A0);\n Serial.println(value);\n delay(100);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot1\", \"top\": 200.3, \"left\": 201.4, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"pot1:GND\", \"uno:GND.2\", \"black\", [ \"v13\", \"h-40\" ] ],\n [ \"pot1:SIG\", \"uno:A0\", \"green\", [ \"v14\", \"h49\", \"v-90\", \"h-66\" ] ],\n [ \"uno:VIN\", \"pot1:VCC\", \"red\", [ \"v20\", \"h76\", \"v79\", \"h-33\" ] ]\n ],\n \"serialMonitor\": { \"display\": \"plotter\" },\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Light intensity measuring using LDR and arduino uno", + "input": "#include \n\n#define LDR_PIN 2\n\n// LDR Characteristics\nconst float GAMMA = 0.7;\nconst float RL10 = 50;\n\nLiquidCrystal_I2C lcd(0x27, 20, 4);\n\nvoid setup() {\n pinMode(LDR_PIN, INPUT);\n\n lcd.init();\n lcd.backlight();\n}\n\nvoid loop() {\n int analogValue = analogRead(A0);\n float voltage = analogValue / 1024. * 5;\n float resistance = 2000 * voltage / (1 - voltage / 5);\n float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));\n\n lcd.setCursor(2, 0);\n lcd.print(\"Room: \");\n if (lux > 50) {\n lcd.print(\"Light!\");\n } else {\n lcd.print(\"Dark \");\n }\n\n lcd.setCursor(0, 1);\n lcd.print(\"Lux: \");\n lcd.print(lux);\n lcd.print(\" \");\n\n delay(100);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 20, \"left\": 20, \"attrs\": {} },\n { \"type\": \"wokwi-lcd1602\", \"id\": \"lcd\", \"top\": 242, \"left\": 50, \"attrs\": { \"pins\": \"i2c\" } },\n {\n \"type\": \"wokwi-photoresistor-sensor\",\n \"id\": \"ldr1\",\n \"top\": -62.39,\n \"left\": 70.26,\n \"attrs\": {}\n }\n ],\n \"connections\": [\n [ \"uno:GND.2\", \"lcd:GND\", \"black\", [ \"v14\", \"*\", \"h-20\" ] ],\n [ \"uno:5V\", \"lcd:VCC\", \"red\", [ \"v18\", \"*\", \"h-16\" ] ],\n [ \"uno:A4\", \"lcd:SDA\", \"green\", [ \"v22\", \"*\", \"h-12\" ] ],\n [ \"uno:A5\", \"lcd:SCL\", \"blue\", [ \"v26\", \"*\", \"h-8\" ] ],\n [ \"uno:GND.1\", \"ldr1:GND\", \"black\", [ \"v-18\", \"h138\", \"v-44\" ] ],\n [ \"ldr1:VCC\", \"uno:5V\", \"red\", [ \"h92\", \"v276\", \"h-145\" ] ],\n [ \"ldr1:AO\", \"uno:A0\", \"orange\", [ \"h69\", \"v241\", \"h-84\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for arduino qr code generator", + "input": "// Arduino QR Code Generator\n// Author: Tomas Hubelbauer\n\n#include // https://github.com/wayoda/LedControl\n#include // https://github.com/ricmoo/QRCode\n\nint size = 6;\nint side = size * 8;\nQRCode qrcode;\n\n// DIN, CLK, CS\nLedControl ledControls[] = {\n LedControl(0, 1, 2, size),\n LedControl(3, 4, 5, size),\n LedControl(6, 7, 8, size),\n LedControl(9, 10, 11, size),\n LedControl(A0, A1, A2, size),\n LedControl(A3, A4, A5, size),\n};\n\nint main() {\n int version = 1;\n uint8_t qrcodeData[qrcode_getBufferSize(version)];\n qrcode_initText(&qrcode, qrcodeData, version, ECC_LOW, \"HUBELBAUER.NET\");\n\n int scale = 2;\n int shift = (side - (qrcode.size * scale)) / 2;\n for (int y = shift; y < side; y++) {\n for (int x = shift; x < side; x++) {\n int index = y / 8;\n int address = size - 1 - (x / 8);\n int row = y % 8;\n int column = 7 - (x % 8);\n\n // Turn out of bounds dots off to make sure they don't stay on\n bool state = false;\n if (x >= shift && x < shift + (qrcode.size * scale) && y >= shift && y < shift + (qrcode.size * scale)) {\n state = qrcode_getModule(&qrcode, (x - shift) / scale, (y - shift) / scale);\n }\n\n ledControls[index].setLed(address, row, column, state);\n }\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Tomas Hubelbauer, Koepel\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-arduino-uno\",\n \"id\": \"u\",\n \"top\": 33.94,\n \"left\": 793.3,\n \"rotate\": 90,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"1\",\n \"top\": 0,\n \"left\": 260,\n \"attrs\": { \"chain\": \"6\", \"color\": \"white\" }\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"2\",\n \"top\": 75,\n \"left\": 260,\n \"attrs\": { \"chain\": \"6\", \"color\": \"white\" }\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"3\",\n \"top\": 150,\n \"left\": 260,\n \"attrs\": { \"chain\": \"6\", \"color\": \"white\" }\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"4\",\n \"top\": 225,\n \"left\": 260,\n \"attrs\": { \"chain\": \"6\", \"color\": \"white\" }\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"5\",\n \"top\": 300,\n \"left\": 260,\n \"attrs\": { \"chain\": \"6\", \"color\": \"white\" }\n },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"6\",\n \"top\": 375,\n \"left\": 260,\n \"attrs\": { \"chain\": \"6\", \"color\": \"white\" }\n }\n ],\n \"connections\": [\n [ \"u:GND.2\", \"1:GND\", \"black\", [ \"*\", \"h6\" ] ],\n [ \"u:5V\", \"1:V+\", \"red\", [ \"*\", \"h12\" ] ],\n [ \"u:0\", \"1:DIN\", \"orange\", [ \"h20\", \"v25\", \"*\", \"h54\" ] ],\n [ \"u:1\", \"1:CLK\", \"blue\", [ \"h23\", \"v38\", \"*\", \"h18\" ] ],\n [ \"u:2\", \"1:CS\", \"green\", [ \"h26\", \"v51\", \"*\", \"h36\" ] ],\n [ \"u:GND.2\", \"2:GND\", \"black\", [ \"*\", \"h6\" ] ],\n [ \"u:5V\", \"2:V+\", \"red\", [ \"*\", \"h12\" ] ],\n [ \"u:3\", \"2:DIN\", \"orange\", [ \"h29\", \"v64\", \"*\", \"h57\" ] ],\n [ \"u:4\", \"2:CLK\", \"blue\", [ \"h32\", \"v77\", \"*\", \"h21\" ] ],\n [ \"u:5\", \"2:CS\", \"green\", [ \"h35\", \"v90\", \"*\", \"h39\" ] ],\n [ \"u:GND.2\", \"3:GND\", \"black\", [ \"*\", \"h6\" ] ],\n [ \"u:5V\", \"3:V+\", \"red\", [ \"*\", \"h12\" ] ],\n [ \"u:6\", \"3:DIN\", \"orange\", [ \"h38\", \"v103\", \"*\", \"h60\" ] ],\n [ \"u:7\", \"3:CLK\", \"blue\", [ \"h41\", \"v116\", \"*\", \"h24\" ] ],\n [ \"u:8\", \"3:CS\", \"green\", [ \"h44\", \"v136\", \"*\", \"h42\" ] ],\n [ \"u:GND.2\", \"4:GND\", \"black\", [ \"*\", \"h6\" ] ],\n [ \"u:5V\", \"4:V+\", \"red\", [ \"*\", \"h12\" ] ],\n [ \"u:9\", \"4:DIN\", \"orange\", [ \"h47\", \"v149\", \"*\", \"h63\" ] ],\n [ \"u:10\", \"4:CLK\", \"blue\", [ \"h50\", \"v162\", \"*\", \"h27\" ] ],\n [ \"u:11\", \"4:CS\", \"green\", [ \"h53\", \"v175\", \"*\", \"h45\" ] ],\n [ \"u:GND.2\", \"5:GND\", \"black\", [ \"*\", \"h6\" ] ],\n [ \"u:5V\", \"5:V+\", \"red\", [ \"*\", \"h12\" ] ],\n [ \"u:A0\", \"5:DIN\", \"orange\", [ \"*\", \"h66\" ] ],\n [ \"u:A1\", \"5:CLK\", \"blue\", [ \"*\", \"h30\" ] ],\n [ \"u:A2\", \"5:CS\", \"green\", [ \"*\", \"h48\" ] ],\n [ \"u:GND.2\", \"6:GND\", \"black\", [ \"*\", \"h6\" ] ],\n [ \"u:5V\", \"6:V+\", \"red\", [ \"*\", \"h12\" ] ],\n [ \"u:A3\", \"6:DIN\", \"orange\", [ \"*\", \"h69\" ] ],\n [ \"u:A4\", \"6:CLK\", \"blue\", [ \"*\", \"h33\" ] ],\n [ \"u:A5\", \"6:CS\", \"green\", [ \"*\", \"h51\" ] ]\n ],\n \"serialMonitor\": { \"display\": \"never\" }\n}" + }, + { + "instruction": "Generate a diagram.json code for volume controller using arduino", + "input": "#include \n#include \n#include \n#include \n\n#define ENCODER_CLK 2\n#define ENCODER_DT 3\n#define ENCODER_SW 4\n\nuint8_t volume = 50;\nuint8_t bass = 25;\nuint8_t treble = 66;\n\ntypedef enum {\n SET_VOLUME,\n SET_BASS,\n SET_TREBLE,\n} Mode;\n\nMode mode = SET_VOLUME;\n\nAdafruit_SSD1306 display(128, 64, &Wire, -1);\n\nvoid nextMode() {\n switch (mode) {\n case SET_VOLUME:\n mode = SET_BASS;\n break;\n\n case SET_BASS:\n mode = SET_TREBLE;\n break;\n\n case SET_TREBLE:\n mode = SET_VOLUME;\n break;\n }\n}\n\nvoid updateValue(int delta) {\n switch (mode) {\n case SET_VOLUME:\n volume = constrain(volume + delta, 0, 100);\n break;\n\n case SET_BASS:\n bass = constrain(bass + delta, 0, 100);\n break;\n\n case SET_TREBLE:\n treble = constrain(treble + delta, 0, 100);\n break;\n }\n}\n\n\n\nvoid updateDisplay() {\n display.clearDisplay();\n display.setFont();\n display.setTextColor(1);\n\n display.setCursor(42, 2);\n display.print(\"Volume\");\n display.drawRoundRect(10, 12, 102, 9, 2, WHITE);\n display.fillRect(11, 13, volume, 7, WHITE);\n if (mode == SET_VOLUME) {\n display.setCursor(32, 2);\n display.print(\">\");\n }\n\n display.setCursor(48, 22);\n display.print(\"Bass\");\n display.drawRoundRect(10, 32, 102, 9, 2, WHITE);\n display.fillRect(11, 33, bass, 7, WHITE);\n if (mode == SET_BASS) {\n display.setCursor(38, 22);\n display.print(\">\");\n }\n\n display.setCursor(42, 42);\n display.print(\"Treble\");\n display.drawRoundRect(10, 52, 102, 9, 2, WHITE);\n display.fillRect(11, 53, treble, 7, WHITE);\n if (mode == SET_TREBLE) {\n display.setCursor(32, 42);\n display.print(\">\");\n }\n\n display.display();\n}\n\nvoid setup() {\n display.begin(SSD1306_SWITCHCAPVCC, 0x3C);\n pinMode(ENCODER_CLK, INPUT);\n pinMode(ENCODER_DT, INPUT);\n pinMode(ENCODER_SW, INPUT_PULLUP);\n updateDisplay();\n}\n\nlong int modeLastChanged = 0;\nint prevClk = HIGH;\nvoid loop() {\n if (digitalRead(ENCODER_SW) == LOW && millis() - modeLastChanged > 300) {\n modeLastChanged = millis();\n nextMode();\n updateDisplay();\n }\n\n int clk = digitalRead(ENCODER_CLK);\n if (clk != prevClk && clk == LOW) {\n int dt = digitalRead(ENCODER_DT);\n int delta = dt == HIGH ? 5 : -5;\n updateValue(delta);\n updateDisplay();\n }\n prevClk = clk;\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-nano\", \"id\": \"uno\", \"top\": -35.94, \"left\": 26.96, \"attrs\": {} },\n { \"type\": \"wokwi-ky-040\", \"id\": \"encoder1\", \"top\": -143.6, \"left\": 60.34, \"attrs\": {} },\n { \"type\": \"wokwi-ssd1306\", \"id\": \"oled1\", \"top\": 63.82, \"left\": 69.64, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"uno:GND.1\", \"oled1:GND\", \"black\", [ \"v19\", \"h5\" ] ],\n [ \"uno:VIN\", \"oled1:VIN\", \"red\", [ \"v24\", \"h-15\" ] ],\n [ \"oled1:DATA\", \"uno:A4\", \"orange\", [ \"v-34\", \"h10\" ] ],\n [ \"oled1:CLK\", \"uno:A5\", \"blue\", [ \"v-30\", \"h5\" ] ],\n [ \"encoder1:CLK\", \"uno:2\", \"purple\", [ \"h42\", \"v85\", \"h-76\" ] ],\n [ \"encoder1:DT\", \"uno:3\", \"green\", [ \"h33\", \"v71\", \"h-73\" ] ],\n [ \"encoder1:SW\", \"uno:4\", \"gray\", [ \"h26\", \"v57\", \"h-75\" ] ],\n [ \"encoder1:VCC\", \"uno:VIN\", \"red\", [ \"h55\", \"v149\", \"h-28\" ] ],\n [ \"encoder1:GND\", \"uno:GND.2\", \"black\", [ \"h18\", \"v32\", \"h-43\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for Date and time reader using ds1307 and arduino uno", + "input": "#include \"RTClib.h\"\n\nRTC_DS1307 rtc;\n\nchar daysOfTheWeek[7][12] = {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"};\n\nvoid setup () {\n Serial.begin(115200);\n\n if (! rtc.begin()) {\n Serial.println(\"Couldn't find RTC\");\n Serial.flush();\n abort();\n }\n}\n\nvoid loop () {\n DateTime now = rtc.now();\n\n Serial.print(\"Current time: \");\n Serial.print(now.year(), DEC);\n Serial.print('/');\n Serial.print(now.month(), DEC);\n Serial.print('/');\n Serial.print(now.day(), DEC);\n Serial.print(\" (\");\n Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);\n Serial.print(\") \");\n Serial.print(now.hour(), DEC);\n Serial.print(':');\n Serial.print(now.minute(), DEC);\n Serial.print(':');\n Serial.print(now.second(), DEC);\n Serial.println();\n\n\n Serial.println();\n delay(3000);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"id\": \"uno\",\n \"type\": \"wokwi-arduino-uno\",\n \"top\": 0,\n \"left\": 20\n },\n {\n \"id\": \"ds1307\",\n \"type\": \"wokwi-ds1307\",\n \"top\": 250,\n \"left\": 220\n }\n ],\n \"connections\": [\n [\"uno:GND.2\", \"ds1307:GND\", \"black\", [\"v20\", \"*\", \"v0\"]],\n [\"uno:5V\", \"ds1307:5V\", \"red\", [\"v0\"]],\n [\"uno:A4\", \"ds1307:SDA\", \"green\", [\"v16\", \"h0\", \"*\", \"h-34\"]],\n [\"uno:A5\", \"ds1307:SCL\", \"orange\", [\"v20\", \"*\", \"h-30\"]]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for Parking sensor using hc-sr04 and arduino uno", + "input": "// I simulate lighting efects on parking sensor lamp\n// It should be a led ring lamp in a garage changing\n// color and flashing by distance.\n\n//Project link in the description :)\n\n// Direction Color State\n// power-up white steady\n// >400 green rotating slowly\n// 200-400 green rotating faster\n// 100-200 yellow --||--\n// 50-100 red fast rotation\n// 50-20 red flashing\n// <20 red/blue flashing\n\n\n// 3rd approach: rotating and changing palette\n// it is too demanding on calculation resources\n// When I saw it finished, I realised it would be easier with FadeToBlackBy()\n// but it is more flexible.\n\n#include \n\n#define TRIG_PIN A3\n#define ECHO_PIN A2\n\n#define LED_PIN 8\n#define NUM_LEDS 16\n#define BRIGHTNESS 255\n#define LED_TYPE WS2812\n#define COLOR_ORDER GRB\nCRGB leds[NUM_LEDS];\n\n#define UPDATES_FREQ 100 // per second\n#define MEASURE_FREQ 2 // per second\n\n#define DISTANCE_MAX 400 // cm\n#define DISTANCE_MIN 0 // cm\n\n\nCRGBPalette16 currentPalette;\nTBlendType currentBlending;\n\nCRGB rgb;\n\nextern const TProgmemPalette16 mySemaphorePalette_p PROGMEM;\n\n/***\n*\n ***\n *\n ***/\nvoid setup() {\n delay(2000);\n\n pinMode(TRIG_PIN, OUTPUT);\n pinMode(ECHO_PIN, INPUT);\n\n // Serial.begin(9600);\n\n FastLED.addLeds(leds, NUM_LEDS); // .setCorrection( TypicalLEDStrip );\n FastLED.setBrightness( BRIGHTNESS );\n\n currentPalette = mySemaphorePalette_p;\n currentBlending = LINEARBLEND;\n\n // blank\n FillColorDelay( CRGB::Yellow, 1000);\n // Serial.println(\" [BEGIN] \");\n\n // blank\n FillColorDelay( CRGB::Black, 1000);\n}\n\n/*\n *\n *\n *\n ****/\nvoid loop() {\n static unsigned int distance = 10;\n static uint8_t colorIndex;\n static byte offset = 0;\n static unsigned int offset_delay = 100; // rotation speed\n\n static unsigned long lastOffsetTime = 0; // last rotation change\n static unsigned long lastMeasureTime = 0; // last use of HC-SR04 sensor\n static unsigned long lastPrintTime = 0; // last Serial.print time\n\n // distance is 200-1500\n // ROTATION SPEED should change 20-1 rotation per second\n offset_delay = map( distance, 20, 400, 20, 100);\n if ( millis() - lastOffsetTime >= offset_delay ) {\n offset = (offset < NUM_LEDS - 1 ? offset + 1 : 0); // increment position\n lastOffsetTime = millis();\n }\n\n // Measure two times per second\n if (millis() - lastMeasureTime >= 1000 / MEASURE_FREQ) {\n distance = get_distance();\n colorIndex = map(distance, DISTANCE_MIN, DISTANCE_MAX, 0, 240);\n // update palette\n newGradientPaletteByDistance(distance);\n lastMeasureTime = millis();\n }\n\n if ( distance > 30 ) {\n FillLEDsFromPalette( offset );\n } else if ( offset % 2 == 0 ) {\n FillColorDelay(CRGB::Blue,200);\n // fill_solid( leds, NUM_LEDS, CRGB::Blue);\n } else {\n FillColorDelay(CRGB::Red,200);\n // fill_solid( leds, NUM_LEDS, CRGB::Red);\n }\n\n // Print only for debugging\n // if (millis() - lastPrintTime >= 2000) {\n // Serial.print(\" [ distance: \"); Serial.print(distance, DEC);\n // Serial.print(\"mm o_delay: \"); Serial.print(offset_delay, DEC);\n // Serial.print(\" index: \"); Serial.print(colorIndex, DEC);\n // Serial.println(\" ] \");\n // lastPrintTime = millis();\n // }\n\n FastLED.show();\n FastLED.delay(1000 / UPDATES_FREQ);\n}\n\n\n// Get color mapped by distance and create gradient palette based by this color\nvoid newGradientPaletteByDistance(int distance) {\n uint8_t xyz[12]; // Needs to be 4 times however many colors are being used.\n // 3 colors = 12, 4 colors = 16, etc.\n CRGB rgb;\n\n rgb = ColorFromPalette( mySemaphorePalette_p, map(distance, DISTANCE_MIN, DISTANCE_MAX, 0, 240), BRIGHTNESS, currentBlending);\n\n // index\n xyz[0] = 0; xyz[1] = rgb.r; xyz[2] = rgb.g; xyz[3] = rgb.b; // anchor of first color - must be zero\n xyz[4] = 40; xyz[5] = rgb.r; xyz[6] = rgb.g; xyz[7] = rgb.b; \n xyz[8] = 255; xyz[9] = 0; xyz[10] = 0; xyz[11] = 0; // anchor of last color - must be 255\n\n currentPalette.loadDynamicGradientPalette(xyz);\n}\n\n\n\n// fill FastLED leds[] strip/ring with colors\nvoid FillLEDsFromPalette( byte offset) {\n //fill_solid( leds, NUM_LEDS, 0);\n\n // One gradient\n for ( int i = 0; i < NUM_LEDS; i++) {\n leds[ i ] = ColorFromPalette( currentPalette, (i+offset) * 255 / (NUM_LEDS - 1), BRIGHTNESS, currentBlending);\n }\n // Two gradients\n // for ( int i = 0; i < NUM_LEDS/2; i++) {\n // leds[ i ] = ColorFromPalette( currentPalette, (i+offset) * 255 / (NUM_LEDS/2 - 1), BRIGHTNESS, currentBlending);\n // leds[ i+(NUM_LEDS/2) ] = leds[i];\n // }\n}\n\n// Fill all leds with one color and wait duration ms\nvoid FillColorDelay ( CRGB color, unsigned long duration ) {\n fill_solid( leds, NUM_LEDS, color);\n FastLED.show();\n FastLED.delay(duration);\n}\n\n\n// This example shows how to set up a static color palette\n// which is stored in PROGMEM (flash), which is almost always more\n// plentiful than RAM. A static PROGMEM palette like this\n// takes up 64 bytes of flash.\nconst TProgmemPalette16 mySemaphorePalette_p PROGMEM = {\n CRGB::Magenta, CRGB::Red, CRGB::Red, CRGB::Red,\n CRGB::Orange, CRGB::Orange, CRGB::Orange, CRGB::Orange,\n CRGB::Yellow, CRGB::Yellow, CRGB::Yellow, CRGB::Green,\n CRGB::Green, CRGB::Green, CRGB::Green, CRGB::White\n};\n\n\n\n// get distance number 0-400 cm\n// use TRIG_PIN and ECHO_PIN of HC-SR04 sensor\nint get_distance() {\n static int distance;\n uint16_t duration = 0;\n uint32_t interval = 0;\n\n digitalWrite(TRIG_PIN, LOW);\n delayMicroseconds(5);\n digitalWrite(TRIG_PIN, HIGH);\n delayMicroseconds(10);\n digitalWrite(TRIG_PIN, LOW);\n\n // Read time of the trig and echo pins\n duration = pulseIn(ECHO_PIN, HIGH);\n // Calculates the distance\n distance = (duration / 2) / 29;\n\n return distance; // centimeters\n}", + "output": "{\n \"version\": 1,\n \"author\": \"stevesigma\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-arduino-nano\",\n \"id\": \"nano\",\n \"top\": 187.29,\n \"left\": 177.88,\n \"rotate\": 180,\n \"hide\": false,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-hc-sr04\",\n \"id\": \"sonar\",\n \"top\": 61.25,\n \"left\": 190.94,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"distance\": \"400\" }\n },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring\",\n \"top\": 57.34,\n \"left\": 32.62,\n \"rotate\": 0,\n \"hide\": false,\n \"attrs\": { \"pixels\": \"16\", \"background\": \"black\" }\n }\n ],\n \"connections\": [\n [ \"nano:5V\", \"sonar:VCC\", \"red\", [ \"*\", \"v20\" ] ],\n [ \"nano:GND.2\", \"sonar:GND\", \"black\", [ \"v20\", \"h130\", \"*\", \"v5\" ] ],\n [ \"nano:A2\", \"sonar:ECHO\", \"orange\", [ \"*\" ] ],\n [ \"nano:A3\", \"sonar:TRIG\", \"white\", [ \"*\" ] ],\n [ \"nano:GND.2\", \"ring:GND\", \"black\", [ \"v20\", \"h-133\", \"*\", \"*\" ] ],\n [ \"nano:8\", \"ring:DIN\", \"green\", [ \"v10\", \"h-180\", \"*\" ] ],\n [ \"nano:5V\", \"ring:VCC\", \"red\", [ \"v-20\", \"h-50\", \"v70\", \"h-70\", \"*\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for digital weight scale using hx711 load cell and arduino uno", + "input": "#include \"HX711_ADC.h\"\n#include \nHX711_ADC LoadCell(9, 8);\nLiquidCrystal_I2C lcd(0x27,16,2);\nconst int buzzer = 11;\nint button1 = 2;\nint button2 = 3;\nint button3 = 4;\nint button4 = 5;\nint taree = 6;\nint num = 1;\nint buttonState = 0; \nint buttonState1 = 0;\nfloat alarm1 = 0;\nfloat alarm2 = 0;\nfloat z1 = 28.3495;\n\n\nunsigned long prevTime1 = millis();\nunsigned long prevTime2 = millis();\n\nlong Time1 = 3000;\nlong Time2 = 1000;\nvoid setup()\n{\n pinMode (button1, INPUT_PULLUP);\n pinMode (button2, INPUT_PULLUP);\n pinMode (button3, INPUT_PULLUP);\n pinMode (button4, INPUT_PULLUP);\n pinMode(buzzer, OUTPUT);\n pinMode (taree, INPUT_PULLUP);\n Serial.begin(9600);\n lcd.init();\n lcd.backlight();\n lcd.clear();\n lcd.setCursor(1, 0);\n lcd.print(\"Weighing Scale\");\n lcd.setCursor(3, 1);\n lcd.print(\"With Alarm\");\n delay(2500);\n lcd.clear();\n delay(150);\n lcd.setCursor(3, 0);\n lcd.print(\"Taring\");\n delay(200);\n lcd.setCursor(9, 0);\n lcd.print(\".\");\n delay(200);\n lcd.setCursor(10, 0);\n lcd.print(\".\");\n delay(200);\n lcd.setCursor(11, 0);\n lcd.print(\".\");\n delay(200);\n lcd.setCursor(12, 0);\n lcd.print(\".\");\n delay(200);\n delay(1000);\n lcd.clear();\n LoadCell.begin(); \n LoadCell.start(1000);\n LoadCell.setCalFactor(0.42);\n \n \n \n\n}\nvoid loop() {\n unsigned long currentTime = millis();\n static unsigned long currentTime1 = millis();\n LoadCell.update(); \n float i = LoadCell.getData(); \n float z = i/28.3495;\n if(digitalRead(button3) == LOW){\n alarm1=0;\n alarm2=0;\n lcd.clear();}\n\n buttonState = digitalRead(button2);\n buttonState1 = digitalRead(button1);\n\n if(buttonState == 0) \n currentTime1 = millis();\n if(buttonState1 == 0)\n currentTime1 = millis();\n\n switch(num){\n case 1:\n {\n if(millis() - currentTime1 >= 4000) // else\n { num = 1;\n } \n else\n num = num; \n break;\n}\ncase 2:\n{\n if(digitalRead(button1) == LOW){alarm1 = alarm1+1;\n delay(75);}\n else if(digitalRead(button2) == LOW){alarm1 = alarm1-1;\n delay(75);}\n if(digitalRead(button3) == LOW)\n alarm1=0;\n lcd.setCursor(1, 0);\n lcd.print(\"Set for Gram\");\n lcd.setCursor(0, 1); // set cursor to secon row\n lcd.print(alarm1, 0); // print out the retrieved value to the second row\n lcd.print(\"g \");\n \n alarm2 = alarm1/z1;\n lcd.setCursor(9, 1);\n lcd.print(alarm2, 1);\n lcd.print(\"oz \");\n\n if(millis() - currentTime1 >= 8000) \n { num = 1;\n lcd.clear();\n lcd.setCursor(1, 0);\n lcd.print(\"Weighing Scale\");\n delay(500);\n lcd.clear();} \n else\n num = num; \n break;}\n case 3:\n {\n if(digitalRead(button1) == LOW){alarm2 = alarm2+1;\n delay(75);}\n else if(digitalRead(button2) == LOW){alarm2 = alarm2-1;\n delay(75);}\n\nlcd.setCursor(1, 0);\n lcd.print(\"Set for Ounce\");\n lcd.setCursor(0, 1); // set cursor to secon row\n lcd.print(alarm1, 0); // print out the retrieved value to the second row\n lcd.print(\"g \");\n alarm1 = alarm2 * z1;\n lcd.setCursor(9, 1);\n lcd.print(alarm2, 1);\n lcd.print(\"oz \");\n\n if(digitalRead(button3) == LOW)\n alarm2=0;\n\n if(millis() - currentTime1 >= 4000) // else\n { num = 1;\n lcd.clear();\n lcd.setCursor(1, 0);\n lcd.print(\"Weighing Scale\");\n delay(500);\n lcd.clear();} \n else\n num = num; \n break;}\n }\n\n \n\n\n\n if (digitalRead (taree) == LOW)\n {\n lcd.clear();\n lcd.setCursor(3, 0);\n lcd.print(\"Taring\");\n delay(200);\n lcd.setCursor(9, 0);\n lcd.print(\".\");\n delay(200);\n lcd.setCursor(10, 0);\n lcd.print(\".\");\n delay(200);\n lcd.setCursor(11, 0);\n lcd.print(\".\");\n delay(200);\n lcd.setCursor(12, 0);\n lcd.print(\".\");\n delay(200);\n delay(500);\n LoadCell.start(1000);\n lcd.setCursor(0, 0);\n lcd.print(\" \");\n lcd.clear();\n }\n if (digitalRead (button4) == LOW){{if(num>2) num = 1;\n else num++;\n currentTime1 = millis();\n delay (300);\n lcd.clear();\n delay (300);\n}\nif (num==3)\n{ lcd.setCursor(1, 0);\n lcd.print(\"Set for Ounce\");\n delay(500);\n lcd.clear();}\n \n else if (num==2)\n {lcd.setCursor(1, 0);\n lcd.print(\"Set for Gram\");\n delay(500);\n lcd.clear();}\n else if (num==1)\n {\n lcd.setCursor(1, 0);\n lcd.print(\"Weighing Scale\");\n delay(500);\n lcd.clear();}\n }\n\nif(currentTime - prevTime1 > Time1){\n \n if(i>alarm1 && alarm1>0 )\n {\n noTone(buzzer);\n delay(300);\n tone(buzzer,250);\n delay(300);\n noTone(buzzer);\n delay(300);\n tone(buzzer,450); \n delay(300);\n noTone(buzzer);\n delay(300);}\n \n prevTime1 = currentTime;\n }\n if(i<-0.9){i==i;} \n else if(-0.9 Time2){\n if (i>=3000 && num<4)\n {\n lcd.clear();\n delay(500);\n num=4;\n }else if(num==4 && i<3000){\n num=1;\n lcd.clear();\n delay(1000);\n }\n if(num==1){\n lcd.setCursor(1, 0);\n lcd.print(\"Weighing Scale\");\n lcd.setCursor(0,1);\n lcd.print(i, 0);\n lcd.print(\"g \");\n lcd.setCursor(9,1);\n lcd.print(z, 1);\n lcd.print(\"oz \");}\nprevTime2 = currentTime;\n if(num==4){\n lcd.setCursor(0, 0);\n lcd.print(\" Over Loaded \"); \n delay(500);\n lcd.clear();\n delay(500);}\n\n \n }\n Serial.print(currentTime);\n Serial.print(\" \");\n Serial.print(millis());\n Serial.print(\" \");\n Serial.print(prevTime2);\n Serial.println(\" \");\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Justine matic013\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -182.77,\n \"left\": 85.42,\n \"attrs\": { \"volume\": \"0.1\" }\n },\n {\n \"type\": \"wokwi-hx711\",\n \"id\": \"hx7\",\n \"top\": 124.2,\n \"left\": 310.51,\n \"attrs\": { \"type\": \"3kg\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": -124.43,\n \"left\": 235.69,\n \"attrs\": { \"color\": \"blue\", \"label\": \"Up\", \"key\": \"1\" }\n },\n {\n \"type\": \"wokwi-lcd1602\",\n \"id\": \"lcd1\",\n \"top\": -327.87,\n \"left\": 97.48,\n \"attrs\": { \"pins\": \"i2c\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn2\",\n \"top\": -120.37,\n \"left\": 322.72,\n \"attrs\": { \"color\": \"blue\", \"label\": \"Down\", \"key\": \"2\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn3\",\n \"top\": -118.96,\n \"left\": 410.54,\n \"attrs\": { \"color\": \"green\", \"label\": \"Reset/Stop\", \"key\": \"3\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn4\",\n \"top\": -116.38,\n \"left\": 503.88,\n \"attrs\": { \"color\": \"red\", \"label\": \"Mode\", \"key\": \"4\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn5\",\n \"top\": -117.37,\n \"left\": 592.34,\n \"attrs\": { \"color\": \"grey\", \"label\": \"Tare\", \"key\": \"5\" }\n }\n ],\n \"connections\": [\n [ \"bz1:2\", \"uno:11\", \"red\", [ \"v36.27\", \"h27.43\" ] ],\n [ \"uno:GND.2\", \"lcd1:GND\", \"black\", [ \"v41.96\", \"h-177.57\", \"v-195.25\" ] ],\n [ \"uno:A4\", \"lcd1:SDA\", \"green\", [ \"v69.2\", \"h-243.29\", \"v-195.81\" ] ],\n [ \"uno:A5\", \"lcd1:SCL\", \"blue\", [ \"v85.1\", \"h-246.54\", \"v-22.7\" ] ],\n [ \"btn2:1.r\", \"uno:3\", \"orange\", [ \"v69.56\", \"h-5.39\" ] ],\n [ \"btn1:2.l\", \"btn2:2.l\", \"black\", [ \"h3.66\", \"v36.06\", \"h88.44\" ] ],\n [ \"btn2:2.l\", \"btn3:2.l\", \"black\", [ \"h0.56\", \"v37.88\", \"h106.82\" ] ],\n [ \"btn3:1.r\", \"uno:4\", \"gold\", [ \"v78.15\", \"h-273.08\" ] ],\n [ \"lcd1:VCC\", \"uno:5V\", \"red\", [ \"h-104.11\", \"v536.86\", \"h16.59\" ] ],\n [ \"btn3:2.l\", \"btn4:2.l\", \"black\", [ \"h-0.06\", \"v35.76\", \"h104.2\" ] ],\n [ \"btn4:1.r\", \"uno:5\", \"blue\", [ \"v88.49\", \"h-361.09\" ] ],\n [ \"uno:GND.1\", \"bz1:1\", \"black\", [ \"v0\" ] ],\n [ \"btn1:1.l\", \"uno:2\", \"green\", [ \"h0\" ] ],\n [ \"uno:GND.1\", \"btn1:2.l\", \"black\", [ \"v0\" ] ],\n [ \"hx7:GND\", \"uno:GND.2\", \"black\", [ \"h0\" ] ],\n [ \"hx7:VCC\", \"uno:5V\", \"red\", [ \"h0\" ] ],\n [ \"btn4:2.l\", \"btn5:2.l\", \"black\", [ \"h-0.19\", \"v32.47\", \"h88.22\" ] ],\n [ \"hx7:DT\", \"uno:9\", \"green\", [ \"h0\" ] ],\n [ \"uno:8\", \"hx7:SCK\", \"green\", [ \"v0\" ] ],\n [ \"uno:6\", \"btn5:1.r\", \"green\", [ \"v-36.51\", \"h460.24\", \"v-82.43\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for LED bar with potentiometer and arduino uno", + "input": "const int analogPin = A0; // the pin that the potentiometer is attached to\nconst int ledCount = 10; // the number of LEDs in the bar graph\n\nint ledPins[] = {\n 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\n}; // an array of pin numbers to which LEDs are attached\n\n\nvoid setup() {\n // loop over the pin array and set them all to output:\n for (int thisLed = 0; thisLed < ledCount; thisLed++) {\n pinMode(ledPins[thisLed], OUTPUT);\n }\n}\n\nvoid loop() {\n // read the potentiometer:\n int sensorReading = analogRead(analogPin);\n // map the result to a range from 0 to the number of LEDs:\n int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);\n\n // loop over the LED array:\n for (int thisLed = 0; thisLed < ledCount; thisLed++) {\n // if the array element's index is less than ledLevel,\n // turn the pin for this element on:\n if (thisLed < ledLevel) {\n digitalWrite(ledPins[thisLed], HIGH);\n }\n // turn off all pins higher than the ledLevel:\n else {\n digitalWrite(ledPins[thisLed], LOW);\n }\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-arduino-uno\",\n \"id\": \"uno\",\n \"top\": 209.75,\n \"left\": -189.97,\n \"rotate\": 90,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-led-bar-graph\",\n \"id\": \"bargraph1\",\n \"top\": 313.04,\n \"left\": 127.68,\n \"attrs\": { \"color\": \"lime\" }\n },\n { \"type\": \"wokwi-resistor\", \"id\": \"r1\", \"top\": 309, \"left\": 190, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r2\", \"top\": 319, \"left\": 190, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r3\", \"top\": 328, \"left\": 190, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r4\", \"top\": 337, \"left\": 190, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r5\", \"top\": 347, \"left\": 190, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r6\", \"top\": 357, \"left\": 190, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r7\", \"top\": 366, \"left\": 190, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r8\", \"top\": 376, \"left\": 190, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r9\", \"top\": 385, \"left\": 190, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r10\", \"top\": 395, \"left\": 190, \"attrs\": {} },\n {\n \"type\": \"wokwi-slide-potentiometer\",\n \"id\": \"pot1\",\n \"top\": 266.78,\n \"left\": -337.42,\n \"rotate\": 270,\n \"attrs\": { \"travelLength\": \"30\" }\n }\n ],\n \"connections\": [\n [ \"bargraph1:A10\", \"uno:2\", \"green\", [ \"h-28\", \"v31\" ] ],\n [ \"bargraph1:A9\", \"uno:3\", \"green\", [ \"h-38\", \"v31\" ] ],\n [ \"bargraph1:A8\", \"uno:4\", \"green\", [ \"h-47\", \"v31\" ] ],\n [ \"bargraph1:A7\", \"uno:5\", \"green\", [ \"h-57\", \"v31\" ] ],\n [ \"bargraph1:A6\", \"uno:6\", \"green\", [ \"h-67\", \"v31\" ] ],\n [ \"bargraph1:A5\", \"uno:7\", \"green\", [ \"h-76\", \"v31\" ] ],\n [ \"bargraph1:A4\", \"uno:8\", \"green\", [ \"h0\" ] ],\n [ \"bargraph1:A3\", \"uno:9\", \"green\", [ \"h0\" ] ],\n [ \"bargraph1:A2\", \"uno:10\", \"green\", [ \"h0\" ] ],\n [ \"bargraph1:A1\", \"uno:11\", \"green\", [ \"h0\" ] ],\n [ \"r1:1\", \"bargraph1:C1\", \"green\", [ \"v0\" ] ],\n [ \"r2:1\", \"bargraph1:C2\", \"green\", [ \"v0\" ] ],\n [ \"r3:1\", \"bargraph1:C3\", \"green\", [ \"v0\" ] ],\n [ \"r4:1\", \"bargraph1:C4\", \"green\", [ \"v0\" ] ],\n [ \"r5:1\", \"bargraph1:C5\", \"green\", [ \"v0\" ] ],\n [ \"r6:1\", \"bargraph1:C6\", \"green\", [ \"v0\" ] ],\n [ \"r7:1\", \"bargraph1:C7\", \"green\", [ \"v0\" ] ],\n [ \"r8:1\", \"bargraph1:C8\", \"green\", [ \"v0\" ] ],\n [ \"r9:1\", \"bargraph1:C9\", \"green\", [ \"v0\" ] ],\n [ \"r10:1\", \"bargraph1:C10\", \"green\", [ \"v0\" ] ],\n [ \"r10:2\", \"r9:2\", \"black\", [ \"v0\" ] ],\n [ \"r8:2\", \"r9:2\", \"black\", [ \"v0\" ] ],\n [ \"r8:2\", \"r7:2\", \"black\", [ \"v0\" ] ],\n [ \"r7:2\", \"r6:2\", \"black\", [ \"v0\" ] ],\n [ \"r6:2\", \"r5:2\", \"black\", [ \"v0\" ] ],\n [ \"r5:2\", \"r4:2\", \"black\", [ \"v0\" ] ],\n [ \"r4:2\", \"r3:2\", \"black\", [ \"v0\" ] ],\n [ \"r3:2\", \"r2:2\", \"black\", [ \"v0\" ] ],\n [ \"r2:2\", \"r1:2\", \"black\", [ \"v0\" ] ],\n [ \"uno:GND.1\", \"r1:2\", \"black\", [ \"h0\" ] ],\n [ \"pot1:GND\", \"uno:GND.2\", \"black\", [ \"v-14\", \"h72\", \"v139\" ] ],\n [ \"pot1:SIG\", \"uno:A0\", \"green\", [ \"v14\", \"h51\", \"v-59\" ] ],\n [ \"uno:VIN\", \"pot1:VCC\", \"red\", [ \"h-48\", \"v72\", \"h-61\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for MPU6050 with arduino uno for 6 axis accel and gyro sensor", + "input": "// originally by Andy Sloane for the Arduboy\n// https://www.a1k0n.net/2017/02/01/arduboy-teapot.html\n\n#include \n#include \"Tiny4kOLED.h\"\n\n#include \n#include \"draw.h\"\n#include \"sincos.h\"\n#include \"vec.h\"\n#include \"teapot.h\"\n\n\nconst int MPU_addr = 0x68; // I2C address of the MPU-6050\nuint8_t screen_[1024];\nint32_t angle_A_ = 0, angle_B_ = 0, angle_C_ = -16384;\nint16_t scale_ = 1024 + 500;\nuint16_t frame_ = 0;\nstatic Vec216 verts[mesh_NVERTS]; // rotated, projected screen space vertices\n\n\nvoid setup(void) {\n Wire.begin();\n oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);\n\n // Initialize the MPU-6050 and test if it is connected.\n Wire.beginTransmission( MPU_addr);\n Wire.write( 0x6B); // PWR_MGMT_1 register\n Wire.write( 0); // set to zero (wakes up the MPU-6050)\n auto error = Wire.endTransmission();\n}\n\nvoid ReadInput() {\n static bool manual_control = false;\n\n Wire.beginTransmission( MPU_addr);\n Wire.write( 0x43); // starting with register 0x43 (GYRO_XOUT_H)\n Wire.endTransmission( false);\n Wire.requestFrom( MPU_addr, 6); // request a total of 6 bytes\n int16_t gx = Wire.read()<<8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)\n int16_t gy = Wire.read()<<8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)\n int16_t gz = Wire.read()<<8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)\n\n if (gx || gy || gz) {\n manual_control = true;\n angle_A_ += gx / 16;\n angle_B_ += gy / 16;\n angle_C_ += gz / 16;\n }\n\n if (!manual_control) {\n angle_A_ += 499;\n angle_B_ += 331;\n angle_C_ += 229;\n }\n}\n\n\n// down-convert signed 1.10 precision to signed 0.7 precision\n// (scaling down from -1024..1024 to -127..127)\nstatic int8_t RescaleR(int16_t x) {\n return ((uint32_t) x*127 + 512) >> 10;\n}\n\nvoid DrawObject() {\n // construct rotation matrix\n int16_t cA, sA, cB, sB, cC, sC;\n\n GetSinCos((angle_A_ >> 6) & 1023, &sA, &cA);\n GetSinCos((angle_B_ >> 6) & 1023, &sB, &cB);\n GetSinCos((angle_C_ >> 6) & 1023, &sC, &cC);\n\n // rotate about X axis by C, then Y axis by B, then Z axis by A\n // [ cA*cB, cB*sA, sB]\n // R = [-cA*sB*sC - cC*sA, cA*cC - sA*sB*sC, cB*sC]\n // [-cA*cC*sB + sA*sC, -cA*sC - cC*sA*sB, cB*cC]\n\n // local coordinate frame given rotation values\n // spend some time up front to get an accurate rotation matrix before\n // rounding to 0.7 fixed point\n // the 32-bit math is only done once per frame, and then we can do\n // all the per-vertex stuff in 8-bit math \n Mat338 rotation_matrix(Vec38(\n RescaleR((int32_t) cA*cB >> 10),\n RescaleR((int32_t) cB*sA >> 10),\n RescaleR(sB)),\n Vec38(\n RescaleR(((int32_t) -cA*sB*sC >> 10) - (int32_t) cC*sA >> 10),\n RescaleR((int32_t) cA*cC - ((int32_t) sA*sB*sC >> 10) >> 10),\n RescaleR((int32_t) cB*sC >> 10)),\n Vec38(\n RescaleR(((int32_t) -cA*cC*sB >> 10) + (int32_t) sA*sC >> 10),\n RescaleR((int32_t) -cA*sC - ((int32_t) cC*sA*sB >> 10) >> 10),\n RescaleR((int32_t) cB*cC >> 10)));\n\n int8_t sortaxis = 0, sortaxisz = rotation_matrix.z.x;\n if (abs(rotation_matrix.z.y) > abs(sortaxisz)) {\n sortaxis = 1;\n sortaxisz = rotation_matrix.z.y;\n }\n if (abs(rotation_matrix.z.z) > abs(sortaxisz)) {\n sortaxis = 2;\n sortaxisz = rotation_matrix.z.z;\n }\n\n rotation_matrix.RotateAndProject(mesh_vertices, mesh_NVERTS, scale_, verts);\n\n // rotate and project all vertices\n /*\n {\n Vec216 *vertptr = verts;\n for (uint16_t j = 0; j < 3*mesh_NVERTS; j += 3) {\n Vec38 obj_vert(\n pgm_read_byte_near(mesh_vertices + j),\n pgm_read_byte_near(mesh_vertices + j + 1),\n pgm_read_byte_near(mesh_vertices + j + 2));\n Vec38 world_vert(\n Fx.dot(obj_vert),\n Fy.dot(obj_vert),\n Fz.dot(obj_vert));\n world_vert.project(scale_, vertptr++);\n }\n }\n */\n\n // back-face cull and sort faces\n for (uint16_t i = 0; i < mesh_NFACES; i++) {\n uint16_t jf = i;\n // use face sort order depending on which axis is most facing toward camera\n if (sortaxisz < 0) {\n jf = mesh_NFACES - 1 - i;\n }\n if (sortaxis == 1) {\n jf = pgm_read_byte_near(mesh_ysort_faces + jf);\n } else if (sortaxis == 2) {\n jf = pgm_read_byte_near(mesh_zsort_faces + jf);\n }\n jf *= 3;\n uint8_t fa = pgm_read_byte_near(mesh_faces + jf),\n fb = pgm_read_byte_near(mesh_faces + jf + 1),\n fc = pgm_read_byte_near(mesh_faces + jf + 2);\n Vec216 sa = verts[fb] - verts[fa];\n Vec216 sb = verts[fc] - verts[fa];\n if ((int32_t) sa.x * sb.y > (int32_t) sa.y * sb.x) { // check winding order\n continue; // back-facing\n }\n\n int8_t illum = rotation_matrix.CalcIllumination(mesh_normals + jf);\n uint8_t pat[4];\n GetDitherPattern(illum, pat);\n FillTriangle(\n verts[fa].x, verts[fa].y,\n verts[fb].x, verts[fb].y,\n verts[fc].x, verts[fc].y,\n pat, screen_);\n }\n}\n\n\nclass Stars {\n static const int kNumStars = 30;\n uint16_t wyhash16_x;\n\n private:\n // https://github.com/littleli/go-wyhash16/blob/master/wyhash16.go\n uint32_t hash16(uint32_t input, uint32_t key) {\n uint32_t hash = input * key;\n return ((hash >> 16) ^ hash) & 0xFFFF;\n }\n\n uint16_t wyhash16() {\n wyhash16_x += 0xfc15;\n return hash16(wyhash16_x, 0x2ab);\n }\n\n public:\n void Draw() {\n wyhash16_x = 0xabcd; // reseed our private PRNG\n for (uint8_t i = 0; i < kNumStars; i++) {\n uint16_t randval = wyhash16();\n uint8_t xpos = randval ^ (randval >> 8);\n uint8_t ypos = (randval >> 8) & 63;\n uint8_t xspeed = 1 + ((randval + (randval >> 13)) & 7);\n \n uint16_t page = (ypos >> 3) << 7;\n uint8_t mask = 1 << (ypos & 7);\n uint8_t x = xpos - xspeed * frame_;\n x >>= 1;\n screen_[page + x] |= mask;\n }\n }\n};\n\nStars stars_;\n\nvoid loop(void) {\n memset(screen_, 0, 1024);\n stars_.Draw();\n ReadInput();\n DrawObject();\n\n uint8_t *addr = screen_;\n for (uint8_t y = 0; y < 8; y++) {\n oled.setCursor(0, y);\n oled.startData();\n for (uint8_t i = 0; i < 128; i++)\n oled.sendData(*addr++);\n oled.endData();\n }\n frame_++;\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Andy Sloane (a1kon)\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-arduino-uno\",\n \"id\": \"uno\",\n \"top\": 30,\n \"left\": 134.67,\n \"rotate\": 90,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-mpu6050\", \"id\": \"mpu\", \"top\": 170, \"left\": 25, \"rotate\": 270, \"attrs\": {} },\n { \"type\": \"wokwi-ssd1306\", \"id\": \"oled1\", \"top\": 267.02, \"left\": 28.5, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 190,\n \"left\": 110,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 190,\n \"left\": 90,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"10000\" }\n }\n ],\n \"connections\": [\n [ \"uno:5V\", \"mpu:VCC\", \"red\", [ \"h-157\", \"v9\" ] ],\n [ \"uno:5V\", \"r1:1\", \"red\", [ \"h0\" ] ],\n [ \"uno:5V\", \"r2:1\", \"red\", [ \"h0\" ] ],\n [ \"uno:A4\", \"r2:2\", \"LimeGreen\", [ \"h0\" ] ],\n [ \"uno:A4\", \"oled1:DATA\", \"LimeGreen\", [ \"h-79\", \"v9\", \"h-3\" ] ],\n [ \"uno:A4\", \"mpu:SDA\", \"LimeGreen\", [ \"h-79\", \"v9\", \"h-78\", \"v-4\" ] ],\n [ \"uno:A5\", \"r1:2\", \"Gold\", [ \"h0\" ] ],\n [ \"uno:A5\", \"oled1:CLK\", \"Gold\", [ \"h-70\", \"v9\", \"h-1\" ] ],\n [ \"uno:A5\", \"mpu:SCL\", \"Gold\", [ \"h-70\", \"v9\", \"h-96\", \"v-60\" ] ],\n [ \"uno:5V\", \"oled1:VIN\", \"red\", [ \"h-16\", \"v106\", \"h-20\" ] ],\n [ \"uno:GND.2\", \"oled1:GND\", \"black\", [ \"h-23\", \"v92\", \"h-29\" ] ],\n [ \"uno:GND.2\", \"mpu:GND\", \"black\", [ \"h-23\", \"v-15\", \"h-140\", \"v26\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for TM1637 thermometer in pi pico", + "input": "import machine\nimport random\nimport time\nimport tm1637\n\ndisplay = tm1637.TM1637(clk=machine.Pin(16), dio=machine.Pin(17))\n\ndisplay.scroll(\"Pico Thermometer\", delay=200)\ntime.sleep(1)\ndisplay.show(' ')\ntime.sleep(1)\n\ntemp = random.randrange(10,15)\n\nwhile True:\n temp = random.randrange(10,25)\n display.temperature(temp)\n time.sleep(10)", + "output": "{\n \"version\": 1,\n \"author\": \"Luc Volders\",\n \"editor\": \"wokwi\",\n \"parts\": [\n {\n \"type\": \"wokwi-pi-pico\",\n \"id\": \"pico\",\n \"top\": -9.33,\n \"left\": 28,\n \"attrs\": { \"env\": \"micropython-20220117-v1.18\" }\n },\n {\n \"type\": \"wokwi-tm1637-7segment\",\n \"id\": \"sevseg1\",\n \"top\": -127.03,\n \"left\": -124.63,\n \"attrs\": { \"color\": \"red\" }\n }\n ],\n \"connections\": [\n [ \"sevseg1:CLK\", \"pico:GP16\", \"green\", [ \"h70.12\", \"v350.78\" ] ],\n [ \"sevseg1:DIO\", \"pico:GP17\", \"green\", [ \"h76.12\", \"v331.58\" ] ],\n [ \"sevseg1:GND\", \"pico:GND.8\", \"black\", [ \"h104.12\", \"v158.78\" ] ],\n [ \"sevseg1:VCC\", \"pico:VBUS\", \"red\", [ \"h90.78\", \"v149.18\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for Auto room light using arduno nano", + "input": "// **** Students name - Auto Room light\n#include \"oled.h\" //load the oled with Adafruit_SSD1306.h library\n\nvoid setup() {\n setup_oled(); // Start the OLED Display\n}\n\n\nvoid loop() {\n\n SW_check(); //this function does something after checking A0 low\n\n OLED_PRINT(\"All OFF \");\n digitalWrite(2, LOW);\n digitalWrite(3, LOW);\n sdelay(300); //off for 0.3 sec\n\n OLED_PRINT(\"2 ON \");\n digitalWrite(2, HIGH);\n digitalWrite(3, LOW);\n sdelay(200); //blip for 0.2 sec\n}\n\n\nvoid SW_check() {\n if (digitalRead(A0) == LOW) {\n OLED_PRINT(\"RUNNING \");\n digitalWrite(2, HIGH);\n digitalWrite(3, HIGH);\n sdelay(3000);\n }\n\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-nano\", \"id\": \"nano\", \"top\": -148.8, \"left\": -269.3, \"attrs\": {} },\n {\n \"type\": \"board-ssd1306\",\n \"id\": \"oled1\",\n \"top\": -150.46,\n \"left\": -57.37,\n \"attrs\": { \"i2cAddress\": \"0x3c\" }\n },\n { \"type\": \"wokwi-gnd\", \"id\": \"gnd2\", \"top\": -192, \"left\": -58.2, \"attrs\": {} },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": -32.2,\n \"left\": -336,\n \"attrs\": { \"color\": \"yellow\" }\n },\n { \"type\": \"wokwi-gnd\", \"id\": \"gnd3\", \"top\": 67.2, \"left\": -250.2, \"attrs\": {} },\n { \"type\": \"wokwi-vcc\", \"id\": \"vcc1\", \"top\": -229.64, \"left\": -28.8, \"attrs\": {} },\n { \"type\": \"wokwi-gnd\", \"id\": \"gnd1\", \"top\": -201.6, \"left\": -298.2, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": -253.2,\n \"left\": -217,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -253.2,\n \"left\": -178.6,\n \"attrs\": { \"color\": \"cyan\" }\n }\n ],\n \"connections\": [\n [ \"oled1:SCL\", \"nano:A5\", \"green\", [ \"v-28.8\", \"h77.1\", \"v124.8\", \"h-393.6\" ] ],\n [ \"oled1:SDA\", \"nano:A4\", \"green\", [ \"v-19.2\", \"h57.67\", \"v105.6\", \"h-393.6\" ] ],\n [ \"nano:A0\", \"btn1:1.r\", \"green\", [ \"v19.2\", \"h-38.4\" ] ],\n [ \"oled1:VCC\", \"vcc1:VCC\", \"red\", [ \"v0\" ] ],\n [ \"oled1:GND\", \"gnd2:GND\", \"black\", [ \"v-67.2\" ] ],\n [ \"btn1:2.r\", \"gnd3:GND\", \"green\", [ \"h0\" ] ],\n [ \"led2:A\", \"nano:2\", \"green\", [ \"v0\" ] ],\n [ \"led1:A\", \"nano:3\", \"green\", [ \"v28.8\", \"h28.8\" ] ],\n [ \"gnd1:GND\", \"led1:C\", \"black\", [ \"v0\" ] ],\n [ \"led2:C\", \"gnd1:GND\", \"green\", [ \"v9.6\", \"h0.4\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Temperature and humitity measurement", + "input": "#include \n#include \n\n//Pin definitions for the Thermostat components.\n#define DHTPIN 2\n#define DHTTYPE DHT22\n#define RELAY_PIN 8\n#define RED_PIN 9\n#define GREEN_PIN 10\n#define BLUE_PIN 11\n#define INCREASE_BTN 3\n#define DECREASE_BTN 4\n\n//Libraries used for the thermostat project.\nDHT dht(DHTPIN, DHTTYPE);\nLiquidCrystal_I2C lcd(0x27, 16, 2);\n\n//These variable will be used to control the temperature and humidity levels in the thermostat.\n\nfloat currentTemp = 25.0;\nfloat targetTemp = 25.0;\nfloat humidity = 50.0;\n\n\n//Initializaing the Serial monitor, DHT Sensor and LCD.\nvoid setup() {\n Serial.begin(9600);\n dht.begin();\n lcd.init();\n lcd.backlight();\n \n//Set the LED pins as output and button pins as input.\n pinMode(RELAY_PIN, OUTPUT);\n pinMode(RED_PIN, OUTPUT);\n pinMode(GREEN_PIN, OUTPUT);\n pinMode(BLUE_PIN, OUTPUT);\n pinMode(INCREASE_BTN, INPUT_PULLUP);\n pinMode(DECREASE_BTN, INPUT_PULLUP);\n \n// Start with green LED\n setLEDColor(0, 255, 0); \n}\n\nvoid loop() {\n readSensor();\n checkButtons();\n updateLCD();\n controlRelay();\n updateLED();\n delay(100);\n}\n\nvoid readSensor() {\n float newTemp = dht.readTemperature();\n float newHumidity = dht.readHumidity();\n \n if (!isnan(newTemp) && !isnan(newHumidity)) {\n currentTemp = newTemp;\n humidity = newHumidity;\n }\n}\n\n//Controlling the temperature based on the buttons. Buttons upon being pressed, can alter the temperature.\nvoid checkButtons() {\n if (digitalRead(INCREASE_BTN) == LOW) {\n targetTemp += 1;\n delay(200); // Debounce\n }\n if (digitalRead(DECREASE_BTN) == LOW) {\n targetTemp -= 1;\n delay(200); // Debounce\n }\n}\n\n//Display the temperature and humidity level readings on the LCD we've used.\nvoid updateLCD() {\n lcd.clear();\n lcd.setCursor(0, 0);\n lcd.print(\"Temp: \");\n lcd.print(currentTemp, 1);\n lcd.print(\"C \");\n lcd.print(targetTemp, 1);\n lcd.print(\"C\");\n \n lcd.setCursor(0, 1);\n lcd.print(\"Humidity: \");\n lcd.print(humidity, 1);\n lcd.print(\"%\");\n}\n\n//Controlling the relay according to the temperature. If the set temp.> room temp. then the relay turns on the heating. If the set temp.< room temp. then the relay turns off the heating.\nvoid controlRelay() {\n if (currentTemp < targetTemp) {\n digitalWrite(RELAY_PIN, HIGH); // Turn on heating\n } else {\n digitalWrite(RELAY_PIN, LOW); // Turn off heating\n }\n}\n\n//Changing the color of the LED based on the temperature. If the set temp.> current temp. then led turns red. If set temp.< current temp. then led turns blue. If set temp.= current temp. then led turns green.\nvoid updateLED() {\n if (currentTemp < targetTemp) {\n setLEDColor(0, 0, 255); // Blue\n } else if (currentTemp > targetTemp) {\n setLEDColor(255, 0, 0); // Red\n } else {\n setLEDColor(0, 255, 0); // Green\n }\n}\n\nvoid setLEDColor(int red, int green, int blue) {\n analogWrite(RED_PIN, red);\n analogWrite(GREEN_PIN, green);\n analogWrite(BLUE_PIN, blue);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard\", \"id\": \"bb1\", \"top\": -31.8, \"left\": 319.6, \"attrs\": {} },\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 288.6, \"left\": 393, \"attrs\": {} },\n {\n \"type\": \"wokwi-rgb-led\",\n \"id\": \"rgb1\",\n \"top\": -5.6,\n \"left\": 711.5,\n \"attrs\": { \"common\": \"cathode\" }\n },\n { \"type\": \"wokwi-dht22\", \"id\": \"dht1\", \"top\": -28.5, \"left\": 589.8, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 90.65,\n \"left\": 555.4,\n \"rotate\": 180,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn1\",\n \"top\": 28.2,\n \"left\": 435,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-pushbutton\",\n \"id\": \"btn2\",\n \"top\": 28.2,\n \"left\": 329.4,\n \"rotate\": 90,\n \"attrs\": { \"color\": \"blue\" }\n },\n {\n \"type\": \"wokwi-lcd1602\",\n \"id\": \"lcd1\",\n \"top\": 227.2,\n \"left\": 831.2,\n \"attrs\": { \"pins\": \"i2c\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 81.6,\n \"left\": 690.65,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 81.6,\n \"left\": 709.85,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r4\",\n \"top\": 81.6,\n \"left\": 719.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r5\",\n \"top\": 90.35,\n \"left\": 374.4,\n \"attrs\": { \"value\": \"10000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r6\",\n \"top\": 90.35,\n \"left\": 480,\n \"attrs\": { \"value\": \"10000\" }\n },\n { \"type\": \"wokwi-relay-module\", \"id\": \"relay1\", \"top\": 240.2, \"left\": 220.8, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"uno:5V\", \"bb1:bp.1\", \"red\", [ \"v47.9\", \"h-188.2\" ] ],\n [ \"uno:GND.3\", \"bb1:bn.1\", \"black\", [ \"v76.7\", \"h-206.4\" ] ],\n [ \"bb1:23b.h\", \"bb1:28b.h\", \"red\", [ \"v0\" ] ],\n [ \"bb1:23b.i\", \"bb1:bp.18\", \"red\", [ \"v0\" ] ],\n [ \"bb1:31b.i\", \"bb1:bn.25\", \"black\", [ \"v0\" ] ],\n [ \"lcd1:SDA\", \"uno:A4\", \"cyan\", [ \"h-38.4\", \"v221\", \"h-157.8\" ] ],\n [ \"lcd1:SCL\", \"uno:A5\", \"magenta\", [ \"h-19.2\", \"v441.9\" ] ],\n [ \"lcd1:GND\", \"bb1:bn.37\", \"black\", [ \"h0\" ] ],\n [ \"lcd1:VCC\", \"bb1:bp.37\", \"red\", [ \"h-67.2\", \"v-114.2\" ] ],\n [ \"bb1:4b.h\", \"bb1:bn.2\", \"black\", [ \"v0\" ] ],\n [ \"bb1:15b.h\", \"bb1:bn.11\", \"black\", [ \"v0\" ] ],\n [ \"bb1:13b.g\", \"uno:3\", \"red\", [ \"v144\", \"h153.6\" ] ],\n [ \"bb1:29b.h\", \"uno:2\", \"yellow\", [ \"v96\", \"h9.6\" ] ],\n [ \"bb1:41t.e\", \"bb1:bn.33\", \"black\", [ \"v0\" ] ],\n [ \"bb1:2b.g\", \"uno:4\", \"blue\", [ \"v105.6\", \"h230.4\" ] ],\n [ \"relay1:VCC\", \"bb1:bp.6\", \"red\", [ \"h-19.2\", \"v-38.4\", \"h230.4\" ] ],\n [ \"relay1:IN\", \"uno:8\", \"white\", [ \"h-38.4\", \"v67\", \"h384\" ] ],\n [ \"relay1:GND\", \"bb1:bn.6\", \"black\", [ \"h-19.2\", \"v47.6\", \"h211.2\" ] ],\n [ \"bb1:40b.j\", \"uno:11\", \"red\", [ \"v134.4\", \"h-134.4\" ] ],\n [ \"bb1:42b.j\", \"uno:10\", \"limegreen\", [ \"v144\", \"h-182.4\" ] ],\n [ \"bb1:43b.j\", \"uno:9\", \"cyan\", [ \"v153.6\", \"h-192\" ] ],\n [ \"rgb1:R\", \"bb1:40t.c\", \"\", [ \"$bb\" ] ],\n [ \"rgb1:COM\", \"bb1:41t.d\", \"\", [ \"$bb\" ] ],\n [ \"rgb1:G\", \"bb1:42t.c\", \"\", [ \"$bb\" ] ],\n [ \"rgb1:B\", \"bb1:43t.c\", \"\", [ \"$bb\" ] ],\n [ \"dht1:VCC\", \"bb1:28b.f\", \"\", [ \"$bb\" ] ],\n [ \"dht1:SDA\", \"bb1:29b.f\", \"\", [ \"$bb\" ] ],\n [ \"dht1:NC\", \"bb1:30b.f\", \"\", [ \"$bb\" ] ],\n [ \"dht1:GND\", \"bb1:31b.f\", \"\", [ \"$bb\" ] ],\n [ \"r1:1\", \"bb1:29b.g\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"bb1:23b.g\", \"\", [ \"$bb\" ] ],\n [ \"btn1:1.l\", \"bb1:15t.a\", \"\", [ \"$bb\" ] ],\n [ \"btn1:2.l\", \"bb1:13t.a\", \"\", [ \"$bb\" ] ],\n [ \"btn1:1.r\", \"bb1:15b.f\", \"\", [ \"$bb\" ] ],\n [ \"btn1:2.r\", \"bb1:13b.f\", \"\", [ \"$bb\" ] ],\n [ \"btn2:1.l\", \"bb1:4t.a\", \"\", [ \"$bb\" ] ],\n [ \"btn2:2.l\", \"bb1:2t.a\", \"\", [ \"$bb\" ] ],\n [ \"btn2:1.r\", \"bb1:4b.f\", \"\", [ \"$bb\" ] ],\n [ \"btn2:2.r\", \"bb1:2b.f\", \"\", [ \"$bb\" ] ],\n [ \"r2:1\", \"bb1:40t.e\", \"\", [ \"$bb\" ] ],\n [ \"r2:2\", \"bb1:40b.i\", \"\", [ \"$bb\" ] ],\n [ \"r3:1\", \"bb1:42t.e\", \"\", [ \"$bb\" ] ],\n [ \"r3:2\", \"bb1:42b.i\", \"\", [ \"$bb\" ] ],\n [ \"r4:1\", \"bb1:43t.e\", \"\", [ \"$bb\" ] ],\n [ \"r4:2\", \"bb1:43b.i\", \"\", [ \"$bb\" ] ],\n [ \"r5:1\", \"bb1:4b.g\", \"\", [ \"$bb\" ] ],\n [ \"r5:2\", \"bb1:10b.g\", \"\", [ \"$bb\" ] ],\n [ \"r6:1\", \"bb1:15b.g\", \"\", [ \"$bb\" ] ],\n [ \"r6:2\", \"bb1:21b.g\", \"\", [ \"$bb\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Telephone dialer using buzzr with arduino-nano", + "input": "// Arduino Phone Dialer.\n// Uses the pulse dialing method to dial a phone number.\n \nint offtimer = 60; // The higher the number, the slower the timing.\nint ontimer = 30;\nuint8_t phone_number[] = {1,2,3,4,5,6,7,8,9,0}; // the phone number to dial\n//int number_length = 9; // the number of digits in the phone number (i.e. the length of the array)\nint out=13; // the output pin to the pulsing relay\nint didthis=0;\nuint8_t DebugModeSerial = 1;\n\n//DTMF--------------------------\n#include \"Tone.h\"\n\nTone freq1;\nTone freq2;\n\nconst int DTMF_freq1[] = { 1336, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1336, 1477 };\nconst int DTMF_freq2[] = { 941, 697, 697, 697, 770, 770, 770, 852, 852, 852 };\n\n//DTMF--------------------------\n\n\n\n\nvoid setup(){\n Serial.begin(115200);\n pinMode(out, OUTPUT); // define pin as output.\n\n freq1.begin(3);\n freq2.begin(4);\n}\n\nvoid loop(){\n if(didthis == 0){\n digitalWrite(out, HIGH); // turn on the relay to establish a connection to the phone (i.e. plugging in the phone)\n delay (1000);\n //uint8_t Phone_number[] = {1,2,3,4,5,6,7,8,9,0};\n Pulse_Dialer(phone_number,sizeof(phone_number));\n }\n didthis=1;\n digitalWrite(out, HIGH); // turn the relay ON to keep the phone on the line and wait for the other end to ring.\n\n DTMF_Dialing();\n}\n\nvoid Pulse_Dialer(uint8_t phone_number[],uint8_t Phone_Len){\n for(int count=0; count \n#include \n#include \"RTClib.h\"\n\n#include \n#include \n#include \n\nLiquidCrystal_I2C lcd(0x27, 20, 4);\n\n#define AVG_NUM 10\n#define offsetVoltage 2.5 // for ACS712 sensor\n#define Sensitivity 0.066 // 66mV/A for ACS712-30A variant \n#define Sensitivity1 0.04 // 40mV/A for ACS758 -50A variant\n\n#define PV_volt_pin 34 // defining the analog pin ADC1_CH6 to read solar panel Voltage\n#define PV_current_pin 35 //defining the Analog pin ADC1_CH7 to measure solar current\n#define bat_volt_pin 32 //defining the analog pin ADC1_CH4 to read battery voltage\n#define bat_current_pin 33 //defining the Analog pin ADC1_CH5 to measure battery current\n#define inv_volt_pin 25 //defining the Analog pin ADC2_CH8 to measure inverter input volt\n#define inv_current_pin 26 //defining the Analog pin ADC2_CH9 to measure inverter input current\n#define load_volt_pin 12 //defining the Analog pin ADC2_CH5 to measure DC load output volt\n#define load_current_pin 27 //defining the Analog pin ADC2_CH7 to measure DC load output current\n#define pwm_pin 14 //PWM Pin GPIO14 conncet to MOsfet Driver \n#define DCload_pin 13 // Defining DC load control pin GPIO 13 to drive MOSFET Q2\n\n#define BULK_CHRARGE_SP 14.4\n#define FLOAT_CHARGE_SP 13.5\n#define Charge_Restart_SP 13.2\n#define MIN_SOLAR_VOLT 10\n#define LVD 11.5\n#define LVR 12.5\n#define ABSORPTION_LIMIT 3600000 // 1 hour in milliseconds\n#define NIGHT_TIME 3600000 // 1 hour in milliseconds\n#define CHARGER_RESTART_TIME 600000 // 10 mins in milliseconds\n#define EVENING_TIME 300000 // 5mins in milliseconds\n#define MORNING_TIME 180000 // 3mins in milliseconds\n#define DCLOAD_VOLT_SP 12.3\n\n#define gradDetect 26.3157894373 // Gradient for SoC Detect \n#define Vb_FULL_SCALE 13.8 //SoC 100% Baterai 13.8 Volt\n\nconst int PWM_CHANNEL = 0; // ESP32 has 16 channels which can generate 16 independent waveforms\nconst int PWM_FREQ = 980.39; // Recall that Arduino Uno is ~490 Hz. Official ESP32 example uses 5,000Hz\nconst int PWM_RESOLUTION = 8; // We'll use same resolution as Uno (8 bits, 0-255) but ESP32 can go up to 16 bits \n\n// The max duty cycle value based on PWM resolution (will be 255 if resolution is 8 bits)\nconst int MAX_DUTY_CYCLE = (int)(pow(2, PWM_RESOLUTION) - 1); \nconst int DELAY_MS = 4; // delay between fade increments\n\nfloat PV_volt=0; // solar panel voltage \nfloat PV_current=0; // solar panel current \nfloat bat_volt=0; // Battery voltage \nfloat bat_current=0; //Battery current (Charge pr Discharge)\nfloat inv_volt=0; // Inverter voltage input\nfloat inv_current=0; // Inverter current input\nfloat load_volt=0; // DC Load current\nfloat load_current=0; // DC Load current\n\nfloat PV_watts=0; //PV Watt\nfloat PV_wattHours=0; //PV Watt Hours-Calculate\n\nfloat load_watts=0; //DC Load watt\n\nfloat pwm_duty=0; // PWM Duty Cycle (0 to 255)\nfloat pwm_dutyDC=0; // PWM Duty Cycle (0 to 255)\nfloat bulk_charge_sp=0; // Bulk charging set point\nfloat float_charge_sp=0; // Float charging set point\nint load_status; // 0-off, 1- on \nconst int bat_type = 1; //Flooded=0,AGM=1 \n\nint celsius=36;\nint temp_change=0;\nfloat temp_val=0;\n\nint disp,dcloadstate;\n\nunsigned long last_time=0;\nunsigned long current_time=0;\n\nunsigned long absorption_time; // to keep track of today's time in absorption state\nunsigned long charger_millis; // to keep track of time for charger\nunsigned long restart_time;\nunsigned long load_millis;\n\nint mode =1;\n\nfloat SoC_Detect = 0;\nfloat temp_SoC_Detect =0;\nfloat SoCCorr_k_1 =0;\nfloat SoC_VB=0;\nint SOC_VB_Temp =0;\nfloat bat_volt_k_1 =0;\nfloat persen1;\nint persen;\n\n//***************************PID Controller***********************************\ndouble Sp, input_val, u;\nPID myPID(&input_val, &u, &Sp,2,5,1, DIRECT); //Kp= 2 , Ki= 5 and Kd=1\n\nenum charger_state {off, bulk,absorption,Float} charger_state ; \n\n///////////////////////DECLARATION OF ALL BIT MAP ARRAY FOR FONTS////////////////////////////////////////////////////////////////\n//--------------------------------------------------------------------------------------------------------------------------\n\nbyte solar[8] = //icon for solar panel\n{\n 0b11111,0b10101,0b11111,0b10101,0b11111,0b10101,0b11111,0b00000\n};\nbyte battery[8] = //icon for battery\n{\n 0b01110,0b11011,0b10001,0b10001,0b10001,0b10001,0b10001,0b11111\n};\nbyte charge[8] = // icon for battery charge\n{\n 0b01010,0b11111,0b10001,0b10001,0b10001,0b01110,0b00100,0b00100,\n};\nbyte not_charge[8]=\n{\n 0b00000,0b10001,0b01010,0b00100,0b01010,0b10001,0b00000,0b00000,\n};\nbyte temp[8] = //icon for termometer\n{\n 0b00100,0b01010,0b01010,0b01110,0b01110,0b11111,0b11111,0b01110\n};\nbyte energy[8] = // icon for power\n{\n 0b00010,0b00100,0b01000,0b11111,0b00010,0b00100,0b01000,0b00000\n};\nbyte PWM[8] = {\n B11101,\n B10101,\n B10101,\n B10101,\n B10101,\n B10101,\n B10101,\n B10111\n};\n\n//**************SoC Detect*************************************************\nfloat SOC_Detect()\n{\n SoC_Detect = (gradDetect*(bat_volt - 10.0));\n return SoC_Detect;\n}\n\nvoid SoC_Estimator(float SOCCOOR_K_1, float BAT_VOLT_K_1, float BAT_VOLT,float *SOC_VB)\n{\n *SOC_VB = SOCCOOR_K_1 + ((BAT_VOLT - BAT_VOLT_K_1)/(Vb_FULL_SCALE - BAT_VOLT_K_1 )*(100 - SOCCOOR_K_1));\n}\n\nvoid INIT(int DCloadstate)\n{\n //**********************Raw 0 (SOLAR INDICATOR)***********************\n lcd.setCursor(0, 0); //(Kolom, Baris)\n lcd.print(\"SOL\");\n\n lcd.createChar(0, solar);\n lcd.setCursor(4, 0); //(Kolom, Baris)\n lcd.write(0);\n\n lcd.setCursor(0, 1); //(Kolom, Baris)\n lcd.print(PV_volt,1);\n\n lcd.setCursor(4, 1); //(Kolom, Baris)\n lcd.print('V');\n\n lcd.setCursor(0, 2); //(Kolom, Baris)\n lcd.print(PV_current,1);\n\n lcd.setCursor(4, 2); //(Kolom, Baris)\n lcd.print('A');\n\n lcd.setCursor(0, 3); //(Kolom, Baris)\n lcd.print(PV_watts);\n\n lcd.setCursor(4, 3); //(Kolom, Baris)\n lcd.print('W');\n\n //*******************Raw 1 (BATTERAI INDICATOR)********************************************\n lcd.setCursor(7, 0); //(Kolom, Baris)\n lcd.print(\"BAT\");\n\n lcd.createChar(1, battery);\n lcd.setCursor(11, 0); //(Kolom, Baris)\n lcd.write(1);\n\n lcd.setCursor(7, 1); //(Kolom, Baris)\n lcd.print(bat_volt,1);\n\n lcd.setCursor(11, 1); //(Kolom, Baris)\n lcd.print('V');\n\n lcd.setCursor(7, 2); //(Kolom, Baris)\n lcd.print(bat_current,1);\n\n lcd.setCursor(11, 2); //(Kolom, Baris)\n lcd.print('A');\n\n lcd.createChar(2, charge);\n lcd.setCursor(7, 3); //(Kolom, Baris)\n lcd.write(2);\n\n if(disp == 0)\n {\n lcd.createChar(3, not_charge); //menampilkan ke Display kondisi sedang tidak melakukan charging\n lcd.setCursor(8, 3); //(Kolom, Baris)\n lcd.write(3);\n }\n else if(disp == 1)\n {\n lcd.setCursor(8, 3); //(Kolom, Baris)\n lcd.print('B'); //menampilkan ke Display kondisi charging mode Bulk Charging\n }\n else if(disp == 2)\n {\n lcd.setCursor(8, 3); //(Kolom, Baris)\n lcd.print('A'); //menampilkan ke Display kondisi charging mode Float Charging\n }\n\n else if(disp == 3)\n {\n lcd.setCursor(8, 3); //(Kolom, Baris)\n lcd.print('F'); //menampilkan ke Display kondisi charging mode absorption Charging\n }\n\n if(SOC_VB_Temp == 0)\n {\n lcd.setCursor(9, 3); //(Kolom, Baris)\n lcd.print(' ');\n }\n else\n {\n lcd.setCursor(9, 3); //(Kolom, Baris)\n lcd.print(SOC_VB_Temp);\n }\n\n lcd.setCursor(11, 3); //(Kolom, Baris)\n lcd.print(\"%\");\n\n //*******************Raw 12 (PWM INDICATOR)********************************************\n lcd.setCursor(14, 0); //(Kolom, Baris)\n lcd.print(\"PWM\");\n\n lcd.createChar(6, PWM);\n lcd.setCursor(18, 0); //(Kolom, Baris)\n lcd.write(6);\n\n lcd.setCursor(15, 1); //(Kolom, Baris)\n lcd.print(persen); // satuan pwm_duty dalam persen\n lcd.print(\"% \"); \n \n\n lcd.setCursor(13, 2); //(Kolom, Baris)\n lcd.print(\"LOAD DC\"); // satuan pwm_duty dalam persen\n\n if(DCloadstate == 0)\n {\n lcd.setCursor(15, 3); //(Kolom, Baris)\n lcd.print(\"OFF\"); // satuan pwm_duty dalam persen\n }\n else if(DCloadstate == 1)\n {\n lcd.setCursor(15, 3); //(Kolom, Baris)\n lcd.print(\"ON \"); // satuan pwm_duty dalam persen\n }\n \n}\n\nint read_adc(int channel){\n \n int sum = 0;\n int temp;\n int i;\n\n \n for (i=0; i= 1000)\n {\n bat_volt_k_1 = bat_volt;\n SoCCorr_k_1 = temp_SoC_Detect;\n last_time = current_time;\n \n }\n SoC_Estimator(SoCCorr_k_1,bat_volt_k_1,bat_volt,&SoC_VB);\n SOC_VB_Temp = (int) SoC_VB;\n\n if(SOC_VB_Temp > 99)\n {\n SOC_VB_Temp = 99;\n }\n if(SOC_VB_Temp < 0)\n {\n SOC_VB_Temp = 0;\n }\n\n temp_change =celsius-25.0; // 25deg cel is taken as standard room temperature ( STC)\n // for floaded battery\n if (bat_type == 0)\n {\n bulk_charge_sp =BULK_CHRARGE_SP-(0.020*temp_change) ;\n float_charge_sp=FLOAT_CHARGE_SP-(0.020*temp_change) ;\n }\n // for AGM battery // set point is lowered to avoid excess gassing\n else\n {\n bulk_charge_sp =(BULK_CHRARGE_SP-0.2)-(0.020*temp_change) ;\n float_charge_sp=(FLOAT_CHARGE_SP-0.2)-(0.020*temp_change) ;\n }\n\n switch (charger_state) { \n \n case off : \n if (( bat_volt < float_charge_sp) && (PV_volt > (bat_volt + 0.5) )){ \n charger_millis = millis() ;\n charger_state = bulk ; \n }\n else if ( ( bat_volt > float_charge_sp) && (PV_volt > (bat_volt + 0.5)) && (absorption_time > ABSORPTION_LIMIT)){ \n charger_millis = millis() ;\n restart_time = 0 ;\n charger_state = Float ; \n }\n else\n {\n disp=0;\n absorption_time = 0; \n pwm_duty = 0;\n persen1=(pwm_duty/255)*100;\n persen = (int) persen1;\n analogWrite(pwm_pin, pwm_duty);\n }\n break; // end of case off condition\n\n\n // During this stage the MOSFET is fully on by setting the duty cycle to 100%\n // Constant Current Charging\n \n \n case bulk : \n if (PV_volt < bat_volt ){ \n charger_millis = millis();\n charger_state = off;\n disp=0;\n }\n else if ((bat_volt > bulk_charge_sp) && (PV_volt > (bat_volt + 0.5)) && (absorption_time < ABSORPTION_LIMIT)){ \n charger_millis = millis();\n charger_state = absorption;\n disp=2;\n }\n else if ((bat_volt > float_charge_sp) && (PV_volt > (bat_volt + 0.5)) && (absorption_time > ABSORPTION_LIMIT)){ \n charger_millis = millis();\n restart_time = 0;\n charger_state = Float; \n disp=3;\n }\n else{\n disp=1;\n pwm_duty = 255;\n persen1=(pwm_duty/255)*100;\n persen = (int) persen1;\n //ledcWrite(pwm_pin, pwm_duty); //generate PWM from GPIO 14 @ 100% duty // MOSFET Q1 is ON \n analogWrite(pwm_pin, pwm_duty); \n if( bat_volt > bulk_charge_sp )\n {\n charger_state = absorption; \n disp=2;\n }\n }\n break; // end of case bulk condition\n // During this stage the MOSFET is partially on by setting the duty cycle to between 0% and 100%\n // Constant voltage\n case absorption : \n if (PV_volt < bat_volt){ \n charger_millis = millis();\n charger_state = off;\n disp=0;\n }\n else if ((bat_volt > float_charge_sp) && (PV_volt > (bat_volt + 0.5)) && (absorption_time > ABSORPTION_LIMIT)){ \n charger_millis = millis();\n charger_state = Float;\n disp=3;\n }\n else{\n // increment absorption timer and test for duration in absorption state\n absorption_time = absorption_time + millis() - charger_millis ;\n charger_millis = millis();\n disp=2;\n input_val = bat_volt;\n Sp = bulk_charge_sp;\n myPID.Compute(); // Compute PID Output \n pwm_duty = u*5 ; // Output = kp * error + ki * errSum + kd * dErr \n if(pwm_duty < 0)\n {\n pwm_duty=0;\n }\n if(pwm_duty >255)\n {\n pwm_duty=255;\n }\n persen1=(pwm_duty/255)*100; \n persen = (int) persen1;\n //ledcWrite(pwm_pin, pwm_duty); \n analogWrite(pwm_pin, pwm_duty);\n }\n break; // end of case absorption condition\n\n\n // During this stage the MOSFET is partially on by setting the duty cycle between 0% and 100%\n // Constant Voltage Charging\n \n \n case Float : \n if (PV_volt < bat_volt){ \n charger_millis = millis();\n charger_state = off; \n disp=0;\n }\n else if ((bat_volt < Charge_Restart_SP) && (PV_volt > (bat_volt + 0.5) ) && (restart_time > CHARGER_RESTART_TIME)){ \n charger_millis = millis();\n charger_state = bulk; \n disp=1;\n }\n else if ((bat_volt >float_charge_sp) && (PV_volt > (bat_volt + 0.5) ) && ( absorption_time < ABSORPTION_LIMIT)){ \n charger_millis = millis();\n charger_state = absorption;\n disp=2;\n }\n else\n {\n disp=3;\n if (bat_volt > float_charge_sp)\n {\n pwm_duty--;\n if(pwm_duty <0)\n {\n pwm_duty=0;\n }\n persen1=(pwm_duty/255)*100;\n persen = (int) persen1;\n analogWrite(pwm_pin, pwm_duty);\n \n } \n else\n {\n pwm_duty = 12.75; // setting duty cycle = 5% for trickle charge\n persen1=(pwm_duty/255)*100;\n persen = (int) persen1;\n analogWrite(pwm_pin, pwm_duty); //generate PWM from D3 @ 5% duty // Q1 is driving @ 5% duty cycle\n }\n if (bat_volt < Charge_Restart_SP)\n {\n restart_time = restart_time + millis() - charger_millis ;\n charger_millis = millis(); \n }\n }\n break; // end of case float condition\n }\n}\n\nvoid DCLoad_Control()\n{\n PV_volt= read_adc(PV_volt_pin)*0.0048828*(37.5/7.5);\n PV_current = ((read_adc(PV_current_pin)*0.0048828 - offsetVoltage)/ Sensitivity );\n PV_watts = PV_current * PV_volt;\n bat_volt= read_adc(bat_volt_pin)*0.0048828*(37.5/7.5);\n load_volt= read_adc(load_volt_pin)*0.0048828*(37.5/7.5);\n load_current = ((read_adc(load_current_pin)*0.0048828 - offsetVoltage)/ Sensitivity );\n load_watts = load_current * load_volt;\n\n if (PV_current <0 || PV_watts < 0)\n {\n PV_current = 0;\n PV_watts = 0;\n }\n if (bat_current <0)\n {\n bat_current = 0;\n }\n\n if (load_current <0 || load_watts < 0)\n {\n load_current = 0;\n load_watts = 0;\n }\n\n if ((PV_volt < 8.0) && (bat_volt > LVD)) \n {\n\n //DC Load Control Voltage for Constant Voltage in 12V\n if(load_volt > DCLOAD_VOLT_SP)\n {\n pwm_dutyDC--;\n pwm_dutyDC = constrain(pwm_dutyDC,0,254);\n }\n else\n {\n pwm_dutyDC++;\n pwm_dutyDC = constrain(pwm_dutyDC,0,254);\n }\n analogWrite(DCload_pin, pwm_dutyDC); //load will turn on during evening\n dcloadstate =1;\n }\n else if ((PV_volt < 8.0) && (bat_volt < LVD))\n {\n pwm_dutyDC = 0; \n analogWrite(DCload_pin, pwm_dutyDC); // load will turn off during morning\n dcloadstate =0;\n }\n else if (PV_volt > MIN_SOLAR_VOLT)\n {\n pwm_dutyDC = 0; \n analogWrite(DCload_pin, pwm_dutyDC); // load will turn off during morning\n dcloadstate =0;\n }\n else if((bat_volt < LVD) || (load_watts > 60))\n {\n pwm_dutyDC = 0; \n analogWrite(DCload_pin, pwm_dutyDC); // load will turn off during morning\n dcloadstate =0;\n }\n}\n\n\nvoid setup() {\n // put your setup code here, to run once:\n Serial.begin(115200);\n Serial.println(\"Hello, ESP32!\");\n analogReadResolution(10);\n pinMode(pwm_pin, OUTPUT);\n pinMode(DCload_pin, OUTPUT);\n // Sets up a channel (0-15), a PWM duty cycle frequency, and a PWM resolution (1 - 16 bits) \n // ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits);\n // ledcSetup(PWM_CHANNEL, PWM_FREQ, PWM_RESOLUTION);\n // // ledcAttachPin(uint8_t pin, uint8_t channel);\n // ledcAttachPin(pwm_pin, PWM_CHANNEL);\n lcd.init();\n lcd.backlight();\n\n lcd.setCursor(0,0); lcd.print(\"*******************\");\n lcd.setCursor(0,1); lcd.print(\" SOLAR PUMP \"); \n lcd.setCursor(0,2); lcd.print(\" CONTROLLER V00 \"); \n lcd.setCursor(0,3); lcd.print(\"*******************\");\n\n delay(1000);\n lcd.clear();\n input_val = 12;\n Sp= 14.5;\n //turn the PID on\n myPID.SetMode(AUTOMATIC);\n Initial_setpoint();\n INIT(dcloadstate);\n}\n\nvoid loop() {\n // put your main code here, to run repeatedly:\n delay(10); // this speeds up the simulation\n Run_charge();\n INIT(dcloadstate);\n DCLoad_Control();\n Serial.print(pwm_duty);\n Serial.print(\"; \");\n Serial.print(disp);\n Serial.print(\"; \");\n Serial.print(persen1);\n Serial.print(\"; \");\n Serial.print(load_volt);\n Serial.print(\"; \");\n Serial.print(pwm_dutyDC);\n Serial.print(\"\\n\");\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Ilmirrizki Imaduddin\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 76.8, \"left\": -23.96, \"attrs\": {} },\n {\n \"type\": \"wokwi-lcd2004\",\n \"id\": \"lcd1\",\n \"top\": -118.4,\n \"left\": -61.6,\n \"attrs\": { \"pins\": \"i2c\" }\n },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot1\", \"top\": -58.9, \"left\": -384.2, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot2\", \"top\": 37.1, \"left\": -384.2, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot3\", \"top\": 142.7, \"left\": -384.2, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot4\", \"top\": 248.3, \"left\": -384.2, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot5\", \"top\": 411.5, \"left\": -384.2, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot6\", \"top\": 507.5, \"left\": -384.2, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot7\", \"top\": 603.5, \"left\": -384.2, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot8\", \"top\": 709.1, \"left\": -384.2, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": 188.4,\n \"left\": 138.2,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 283.2,\n \"left\": 133.85,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"330\" }\n },\n { \"type\": \"wokwi-led\", \"id\": \"led2\", \"top\": 399.6, \"left\": 23, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 475.2,\n \"left\": 18.65,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"330\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"lcd1:SCL\", \"esp:22\", \"green\", [ \"h-48\", \"v125.1\", \"h211.2\", \"v57.6\" ] ],\n [ \"esp:21\", \"lcd1:SDA\", \"green\", [ \"h57.6\", \"v-76.8\", \"h-220.8\", \"v-144\", \"h9.6\" ] ],\n [ \"lcd1:GND\", \"esp:GND.1\", \"black\", [ \"h-67.2\", \"v28.8\" ] ],\n [ \"lcd1:VCC\", \"esp:5V\", \"red\", [ \"h-86.4\", \"v48.1\" ] ],\n [ \"pot1:GND\", \"pot2:GND\", \"black\", [ \"v0\", \"h-38.4\", \"v115.2\", \"h38.4\" ] ],\n [ \"pot2:GND\", \"pot3:GND\", \"black\", [ \"v28.8\", \"h-48\", \"v96\", \"h48\" ] ],\n [ \"pot3:GND\", \"pot4:GND\", \"black\", [ \"v19.2\", \"h-48\", \"v105.6\", \"h48\" ] ],\n [ \"pot4:GND\", \"pot5:GND\", \"black\", [ \"v19.2\", \"h-48\", \"v163.2\", \"h48\" ] ],\n [ \"pot5:GND\", \"pot6:GND\", \"black\", [ \"v19.2\", \"h-48\", \"v96\", \"h48\" ] ],\n [ \"pot6:GND\", \"pot7:GND\", \"black\", [ \"v19.2\", \"h-48\", \"v96\", \"h48\" ] ],\n [ \"pot1:VCC\", \"pot2:VCC\", \"red\", [ \"v19.2\", \"h37.6\", \"v96\", \"h-38.4\" ] ],\n [ \"pot2:VCC\", \"pot3:VCC\", \"red\", [ \"v19.2\", \"h37.6\", \"v105.6\", \"h-38.4\" ] ],\n [ \"pot3:VCC\", \"pot4:VCC\", \"red\", [ \"v19.2\", \"h37.6\", \"v105.6\", \"h-38.4\", \"v-19.2\" ] ],\n [ \"pot4:VCC\", \"pot5:VCC\", \"red\", [ \"v19.2\", \"h37.6\", \"v163.2\", \"h-38.4\" ] ],\n [ \"pot5:VCC\", \"pot6:VCC\", \"red\", [ \"v19.2\", \"h37.6\", \"v96\", \"h-38.4\" ] ],\n [ \"pot6:VCC\", \"pot7:VCC\", \"red\", [ \"v19.2\", \"h37.6\", \"v96\", \"h-38.4\" ] ],\n [ \"pot1:SIG\", \"esp:34\", \"green\", [ \"v28.8\", \"h182\", \"v96\" ] ],\n [ \"pot2:SIG\", \"esp:35\", \"green\", [ \"v28.8\", \"h86\", \"v9.6\" ] ],\n [ \"pot3:SIG\", \"esp:32\", \"green\", [ \"v28.8\", \"h182\", \"v-76.8\" ] ],\n [ \"pot4:SIG\", \"esp:33\", \"green\", [ \"v38.4\", \"h182\", \"v-182.4\" ] ],\n [ \"pot5:SIG\", \"esp:25\", \"green\", [ \"v28.8\", \"h182\", \"v-307.2\" ] ],\n [ \"pot6:SIG\", \"esp:26\", \"green\", [ \"v19.2\", \"h182\", \"v-297.6\" ] ],\n [ \"pot7:GND\", \"pot8:GND\", \"black\", [ \"v19.2\", \"h-48\", \"v115.2\", \"h48\", \"v-9.6\" ] ],\n [ \"pot7:VCC\", \"pot8:VCC\", \"red\", [ \"v19.2\", \"h37.6\", \"v115.2\", \"h-38.4\" ] ],\n [ \"esp:GND.3\", \"led1:C\", \"black\", [ \"h67.2\", \"v86.4\", \"h9.6\" ] ],\n [ \"led1:A\", \"r1:1\", \"green\", [ \"v0\" ] ],\n [ \"r1:2\", \"esp:13\", \"green\", [ \"h-211.2\", \"v-78\" ] ],\n [ \"led2:C\", \"esp:GND.1\", \"green\", [ \"v0\", \"h-114.8\", \"v-211.2\" ] ],\n [ \"led2:A\", \"r2:1\", \"green\", [ \"v0\" ] ],\n [ \"r2:2\", \"esp:14\", \"green\", [ \"h-105.6\", \"v-298.8\" ] ],\n [ \"pot7:SIG\", \"esp:12\", \"green\", [ \"v38.4\", \"h210.8\", \"v-489.6\", \"h48\" ] ],\n [ \"pot8:SIG\", \"esp:27\", \"green\", [ \"v38.4\", \"h249.2\", \"v-28.8\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for servo control using ESP-32", + "input": "#include \n\nESP32MCPWM motorController;\n\nvoid setup() {\n Serial.begin(115200);\n\n // Attach servo to GPIO pin 5\n motorController.attachServo(5);\n\n // Set initial angle to 0 degrees\n motorController.setServoAngle(0);\n delay(2000);\n\n // Rotate servo to 90 degrees\n motorController.setServoAngle(90);\n delay(2000);\n\n // Rotate servo to 180 degrees\n motorController.setServoAngle(180);\n delay(2000);\n\n // Return servo to 0 degrees\n motorController.setServoAngle(0);\n}\n\nvoid loop() {\n // Add your loop logic here\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Asep Oman Somantri\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"wokwi-servo\", \"id\": \"servo1\", \"top\": 46, \"left\": 182.4, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"servo1:GND\", \"esp:GND.1\", \"black\", [ \"h-28.8\", \"v124.8\", \"h-182.4\", \"v-76.8\", \"h9.6\" ] ],\n [ \"esp:5V\", \"servo1:V+\", \"red\", [ \"h-23.81\", \"v38.4\", \"h0\", \"v0\", \"h182.4\", \"v-124.8\" ] ],\n [ \"esp:5\", \"servo1:PWM\", \"green\", [ \"h0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Gas Leak and Fire Outbreak Monitoring System", + "input": "#include \n#include \n#include \n#include \"Adafruit_MQTT.h\"\n#include \"Adafruit_MQTT_Client.h\"\n#define WIFI_SSID \"Wokwi-GUEST\"\n#define WIFI_PASSWORD \"\"\n#define AIO_SERVER \"io.adafruit.com\"\n#define AIO_SERVERPORT 1883\n#define AIO_USERNAME \"AbhinavAce\"\n#define AIO_KEY \"aio_cXhx00DLUv05w7NRa4eeeJ3bXCT2\"\n\nWiFiClient client;\nAdafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);\nAdafruit_MQTT_Publish sector1_status = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME \"/feeds/sensor data\");\n\nLiquidCrystal_I2C lcd(0x27, 16, 2);\n\nint gas=34;\nint heat=32;\nint led=2;\n\n#define gas_leak 500\n#define fire_break 700\n\nvoid connectWiFi() {\n Serial.print(\"Connecting to WiFi...\");\n WiFi.begin(WIFI_SSID, WIFI_PASSWORD);\n while (WiFi.status() != WL_CONNECTED) {\n delay(500);\n Serial.print(\".\");\n }\n Serial.println(\"Connected!\");\n}\n\nvoid connectMQTT() {\n while (!mqtt.connected()) {\n Serial.print(\"Connecting to MQTT...\");\n if (mqtt.connect()) {\n Serial.println(\"Connected!\");\n } else {\n delay(2000);\n }\n }\n}\n\nvoid setup() {\n Serial.begin(115200);\n lcd.init();\n lcd.backlight();\n lcd.setCursor(0, 0);\n lcd.print(\"Initializing...\");\n // Initialize WiFi and MQTT\n connectWiFi();\n connectMQTT();\n lcd.setCursor(0, 1);\n lcd.print(\"System Ready\");\n delay(2000);\n lcd.clear();\n pinMode(gas,INPUT);\n pinMode(heat,INPUT);\n pinMode(led,OUTPUT);\n}\n\nvoid loop() {\n if (!mqtt.connected()) {\n connectMQTT();}\n mqtt.processPackets(10000);\n mqtt.ping();\n\n int gas1=analogRead(gas);\n int heat1=analogRead(heat);\n bool gasLeak1=gas1>gas_leak;\n bool fire1=heat1\n#include \n#include \n#include \n#include \n#include \"Font7Seg.h\"\n\n// Define the number of devices we have in the chain and the hardware interface\n// NOTE: These pin numbers will probably not work with your hardware and may\n// need to be adapted\n#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW\n#define MAX_DEVICES 4 // Define the number of displays connected\n#define CLK_PIN 13 // CLK or SCK\n#define DATA_PIN 11 // DATA or MOSI\n#define CS_PIN 10 // CS or SS\n#define SPEED_TIME 75 // Speed of the transition\n#define PAUSE_TIME 0\n#define MAX_MESG 20\n\n// These are for the clock\n#define DS1307_ADDRESS 0x68\n\n// These are for the temperature\n#define DHTPIN 2\n#define DHTTYPE DHT22\n#define TIMEDHT 1000\n\n// Global variables\nuint8_t wday, mday, month, year;\nuint8_t hours, minutes, seconds;\n\nchar szTime[9]; // mm:ss\\0\nchar szMesg[MAX_MESG + 1] = \"\";\n\nfloat humidity, celsius, fahrenheit;\n\nuint8_t degC[] = { 6, 3, 3, 56, 68, 68, 68 }; // Deg C\nuint8_t degF[] = { 6, 3, 3, 124, 20, 20, 4 }; // Deg F\n\nuint8_t clear = 0x00;\n\nuint32_t timerDHT = TIMEDHT;\n\nDHT dht(DHTPIN, DHTTYPE);\n\n// Hardware SPI connection\nMD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);\n\nvoid beginDS1307()\n{\n // Read the values \u200b\u200b(date and time) of the DS1307 module\n Wire.beginTransmission(DS1307_ADDRESS);\n Wire.write(clear);\n Wire.endTransmission();\n Wire.requestFrom(DS1307_ADDRESS, 0x07);\n\n seconds = bcdToDec(Wire.read());\n minutes = bcdToDec(Wire.read());\n hours = bcdToDec(Wire.read() & 0xff);\n wday = bcdToDec(Wire.read());\n mday = bcdToDec(Wire.read());\n month = bcdToDec(Wire.read());\n year = bcdToDec(Wire.read());\n}\n\nuint8_t decToBcd(uint8_t value)\n{\n return ((value / 10 * 16) + (value % 10));\n}\n\nuint8_t bcdToDec(uint8_t value)\n{\n return ((value / 16 * 10) + (value % 16));\n}\n\n// Code for reading clock time\nvoid getTime(char *psz, bool f = true)\n{\n sprintf(psz, \"%02d%c%02d\", hours, (f ? ':' : ' '), minutes);\n}\n\n// Code for reading clock date\nvoid getDate(char *psz)\n{\n char szBuf[10];\n sprintf(psz, \"%d %s %04d\", mday , mon2str(month, szBuf, sizeof(szBuf) - 1), (year + 2000));\n}\n\n// Code for get Temperature\nvoid getTemperature()\n{\n // Wait for a time between measurements\n if ((millis() - timerDHT) > TIMEDHT) {\n // Update the timer\n timerDHT = millis();\n\n // Reading temperature or humidity takes about 250 milliseconds!\n // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)\n humidity = dht.readHumidity();\n\n // Read temperature as Celsius (the default)\n celsius = dht.readTemperature();\n\n // Read temperature as Fahrenheit (isFahrenheit = true)\n fahrenheit = dht.readTemperature(true);\n\n // Check if any reads failed and exit early (to try again)\n if (isnan(humidity) || isnan(celsius) || isnan(fahrenheit)) {\n Serial.println(\"Failed to read from DHT sensor!\");\n return;\n }\n }\n}\n\n// Get a label from PROGMEM into a char array\nchar *mon2str(uint8_t mon, char *psz, uint8_t len)\n{\n static const __FlashStringHelper* str[] =\n {\n F(\"Jan\"), F(\"Feb\"), F(\"Mar\"), F(\"Apr\"),\n F(\"May\"), F(\"Jun\"), F(\"Jul\"), F(\"Aug\"),\n F(\"Sep\"), F(\"Oct\"), F(\"Nov\"), F(\"Dec\")\n };\n\n strncpy_P(psz, (const char PROGMEM *)str[mon - 1], len);\n psz[len] = '\\0';\n\n return (psz);\n}\n\nchar *dow2str(uint8_t code, char *psz, uint8_t len)\n{\n static const __FlashStringHelper* str[] =\n {\n F(\"Sunday\"), F(\"Monday\"), F(\"Tuesday\"),\n F(\"Wednesday\"), F(\"Thursday\"), F(\"Friday\"),\n F(\"Saturday\")\n };\n\n strncpy_P(psz, (const char PROGMEM *)str[code - 1], len);\n\n psz[len] = '\\0';\n\n return (psz);\n}\n\nvoid setup(void)\n{\n Wire.begin();\n\n P.begin(2);\n P.setInvert(false);\n\n P.setZone(0, MAX_DEVICES - 4, MAX_DEVICES - 1);\n P.setZone(1, MAX_DEVICES - 4, MAX_DEVICES - 1);\n\n P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);\n P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 0, PA_PRINT , PA_NO_EFFECT);\n\n P.addChar('$', degC);\n P.addChar('&', degF);\n\n dht.begin();\n}\n\nvoid loop(void)\n{\n static uint32_t lastTime = 0; // Memory (ms)\n static uint8_t display = 0; // Current display mode\n static bool flasher = false; // Seconds passing flasher\n\n beginDS1307();\n getTemperature();\n\n P.displayAnimate();\n\n if (P.getZoneStatus(0))\n {\n switch (display)\n {\n case 0: // Temperature deg Celsius\n P.setPause(0, 1000);\n P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_UP);\n display++;\n dtostrf(celsius, 3, 1, szMesg);\n strcat(szMesg, \"$\");\n\n break;\n case 1: // Temperature deg Fahrenheit\n P.setTextEffect(0, PA_SCROLL_UP, PA_SCROLL_DOWN);\n display++;\n dtostrf(fahrenheit, 3, 1, szMesg);\n strcat(szMesg, \"&\");\n\n break;\n case 2: // Humidity\n P.setTextEffect(0, PA_SCROLL_DOWN, PA_SCROLL_LEFT);\n display++;\n dtostrf(humidity, 3, 0, szMesg);\n strcat(szMesg, \"%UR\");\n\n break;\n case 3: // Clock\n P.setFont(0, numeric7Seg);\n P.setTextEffect(0, PA_PRINT, PA_NO_EFFECT);\n P.setPause(0, 0);\n\n if ((millis() - lastTime) >= 1000)\n {\n lastTime = millis();\n getTime(szMesg, flasher);\n flasher = !flasher;\n }\n\n if ((seconds == 00) && (seconds <= 30)) {\n display++;\n P.setTextEffect(0, PA_PRINT, PA_WIPE_CURSOR);\n }\n\n break;\n case 4: // Day of week\n P.setFont(0, nullptr);\n P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);\n display++;\n dow2str(wday, szMesg, MAX_MESG);\n\n break;\n default: // Calendar\n P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);\n display = 0;\n getDate(szMesg);\n\n break;\n }\n\n P.displayReset(0); // Rest zone zero\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked, Anderson Costa\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 120, \"left\": 80, \"attrs\": {} },\n {\n \"type\": \"wokwi-max7219-matrix\",\n \"id\": \"m1\",\n \"top\": 20,\n \"left\": 115,\n \"attrs\": { \"chain\": \"4\" }\n },\n { \"type\": \"wokwi-ds1307\", \"id\": \"ds1307\", \"top\": 254.03, \"left\": 380, \"attrs\": {} },\n {\n \"type\": \"wokwi-dht22\",\n \"id\": \"dht\",\n \"top\": 122.35,\n \"left\": 398.34,\n \"attrs\": { \"color\": \"red\" }\n }\n ],\n \"connections\": [\n [ \"uno:GND.1\", \"m1:GND\", \"black\", [ \"v-12\", \"*\", \"h30\" ] ],\n [ \"uno:10\", \"m1:CS\", \"green\", [ \"v-24\", \"*\", \"h22\" ] ],\n [ \"uno:11\", \"m1:DIN\", \"orange\", [ \"v-20\", \"*\", \"h26\" ] ],\n [ \"uno:13\", \"m1:CLK\", \"blue\", [ \"v-16\", \"*\", \"h18\" ] ],\n [ \"uno:GND.3\", \"ds1307:GND\", \"black\", [ \"v20\", \"*\", \"h-30\" ] ],\n [ \"uno:5V\", \"ds1307:5V\", \"red\", [ \"v35\", \"*\", \"h-15\" ] ],\n [ \"uno:A4\", \"ds1307:SDA\", \"orange\", [ \"v30\", \"*\", \"h-20\" ] ],\n [ \"uno:A5\", \"ds1307:SCL\", \"purple\", [ \"v25\", \"*\", \"h-25\" ] ],\n [ \"uno:2\", \"dht:SDA\", \"yellow\", [ \"v0\", \"h0\", \"*\", \"h-50\", \"v5\" ] ],\n [ \"uno:5V\", \"m1:V+\", \"red\", [ \"v35.21\", \"h247.23\", \"v-310.74\" ] ],\n [ \"uno:5V\", \"dht:VCC\", \"red\", [ \"v35.11\", \"h247.22\", \"v-95.82\", \"h-80.12\" ] ],\n [ \"uno:GND.3\", \"dht:GND\", \"black\", [ \"v20.24\", \"h101.02\", \"v-85\", \"h89.21\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for NLSF595 Arduino Shift Register", + "input": "const int dataPin = 2; /* SI */\nconst int clockPin = 3; /* SCK */\nconst int latchPin = 4; /* RCK */\n\nvoid setup() {\n pinMode(dataPin, OUTPUT);\n pinMode(clockPin, OUTPUT);\n pinMode(latchPin, OUTPUT);\n}\n\nvoid sendData(uint8_t pattern) {\n digitalWrite(latchPin, LOW);\n shiftOut(dataPin, clockPin, LSBFIRST, pattern);\n digitalWrite(latchPin, HIGH);\n}\n\nvoid loop() {\n // Red\n sendData(0b11011011);\n delay(500);\n\n // Green\n sendData(0b10110111);\n delay(500);\n\n // Purple\n sendData(0b01001011);\n delay(500);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Uri Shaked\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 183.33, \"left\": -51.33, \"attrs\": {} },\n {\n \"type\": \"wokwi-nlsf595\",\n \"id\": \"sr1\",\n \"top\": 102.5,\n \"left\": 182.16,\n \"rotate\": 90,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-rgb-led\", \"id\": \"rgb1\", \"top\": -20, \"left\": 3.34, \"attrs\": {} },\n { \"type\": \"wokwi-rgb-led\", \"id\": \"rgb2\", \"top\": -20, \"left\": 101.33, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 75.34,\n \"left\": -18.67,\n \"rotate\": 90,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-resistor\", \"id\": \"r2\", \"top\": 75.34, \"left\": 0, \"rotate\": 90, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 75.33,\n \"left\": 17.34,\n \"rotate\": 90,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-resistor\", \"id\": \"r4\", \"top\": 70, \"left\": 79.34, \"rotate\": 90, \"attrs\": {} },\n { \"type\": \"wokwi-resistor\", \"id\": \"r5\", \"top\": 69.33, \"left\": 98, \"rotate\": 90, \"attrs\": {} },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r6\",\n \"top\": 68.66,\n \"left\": 114.67,\n \"rotate\": 90,\n \"attrs\": {}\n }\n ],\n \"connections\": [\n [ \"sr1:GND\", \"uno:GND.1\", \"black\", [ \"h0\" ] ],\n [ \"sr1:VCC\", \"uno:5V\", \"red\", [ \"h30\", \"v323\", \"h-156\" ] ],\n [ \"sr1:SI\", \"uno:2\", \"blue\", [ \"h16\", \"v70\", \"h-68\" ] ],\n [ \"uno:GND.1\", \"sr1:OE\", \"black\", [ \"v-22\", \"h184\", \"v-52\" ] ],\n [ \"sr1:RCK\", \"uno:4\", \"gray\", [ \"h4\", \"v38\", \"h-66\" ] ],\n [ \"r3:1\", \"rgb1:B\", \"blue\", [ \"h0\" ] ],\n [ \"r2:1\", \"rgb1:G\", \"green\", [ \"h0\" ] ],\n [ \"rgb1:R\", \"r1:1\", \"brown\", [ \"v0\" ] ],\n [ \"rgb2:R\", \"r4:1\", \"brown\", [ \"v0\" ] ],\n [ \"rgb2:G\", \"r5:1\", \"green\", [ \"v0\" ] ],\n [ \"rgb2:B\", \"r6:1\", \"blue\", [ \"v0\" ] ],\n [ \"sr1:QA\", \"r6:2\", \"blue\", [ \"h10.86\", \"v-27.16\", \"h-88.61\", \"v44.05\" ] ],\n [ \"sr1:QC\", \"r4:2\", \"brown\", [ \"h-36.66\", \"v25.24\", \"h-57.6\" ] ],\n [ \"sr1:QB\", \"r5:2\", \"green\", [ \"h-41.46\", \"v30.04\", \"h-33.6\" ] ],\n [ \"sr1:QD\", \"r3:2\", \"blue\", [ \"h-31.86\", \"v20.44\", \"h-124.8\" ] ],\n [ \"sr1:QE\", \"r2:2\", \"green\", [ \"h-22.26\", \"v15.64\", \"h-148.8\" ] ],\n [ \"sr1:QF\", \"r1:2\", \"brown\", [ \"h-17.46\", \"v10.84\", \"h-172.8\" ] ],\n [ \"rgb2:COM\", \"rgb1:COM\", \"red\", [ \"v9\", \"h-97.75\" ] ],\n [ \"uno:5V\", \"rgb1:COM\", \"red\", [ \"v19.59\", \"h-164.65\", \"v-351\", \"h77.65\" ] ],\n [ \"sr1:SCK\", \"uno:3\", \"purple\", [ \"h8.28\", \"v33\", \"h-67.15\" ] ]\n ]\n}" + }, + { + "instruction": "Generate a diagram.json code for LED with switch using arduino-uno", + "input": "//int buttonPin = 2; // Button connected to pin 2\nint ledPin = 13; // LED connected to pin 13\n//int buttonState = 0;\n\nvoid setup() {\n pinMode(2, INPUT_PULLUP); // Set the button pin as input.\n pinMode(ledPin, OUTPUT); // Set the LED pin as output.\n}\n\nvoid loop() {\n digitalRead(2); // Read the button state.\n\n if (digitalRead(2) == LOW) { // If the button is pressed\n digitalWrite(ledPin, HIGH); // Turn on the LED.\n } else {\n digitalWrite(ledPin, LOW); // Turn off the LED.\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Yuvaraj s\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n {\n \"type\": \"wokwi-pushbutton-6mm\",\n \"id\": \"btn1\",\n \"top\": -69.4,\n \"left\": 240,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": -63.25,\n \"left\": 144,\n \"attrs\": { \"value\": \"1000\" }\n },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -99.6, \"left\": 90.2, \"attrs\": { \"color\": \"red\" } }\n ],\n \"connections\": [\n [ \"led1:A\", \"r1:1\", \"green\", [ \"v0\" ] ],\n [ \"r1:2\", \"uno:13\", \"green\", [ \"v38.4\", \"h-78\" ] ],\n [ \"btn1:2.l\", \"uno:2\", \"green\", [ \"h0\" ] ],\n [ \"led1:C\", \"uno:GND.1\", \"green\", [ \"v48\", \"h10\" ] ],\n [ \"btn1:1.r\", \"uno:GND.1\", \"green\", [ \"v-48\", \"h-181.6\", \"v96\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for multi-colour LED", + "input": "void setup() {\npinMode(4, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 4 \u0e40\u0e1b\u0e47\u0e19 OUTPUT\npinMode(5, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 5 \u0e40\u0e1b\u0e47\u0e19 OUTPUT\npinMode(6, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 6 \u0e40\u0e1b\u0e47\u0e19 OUTPUT\npinMode(7, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 7 \u0e40\u0e1b\u0e47\u0e19 OUTPUT \npinMode(8, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 8 \u0e40\u0e1b\u0e47\u0e19 OUTPUT\npinMode(9, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 9 \u0e40\u0e1b\u0e47\u0e19 OUTPUT\npinMode(10, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 10 \u0e40\u0e1b\u0e47\u0e19 OUTPUT\npinMode(11, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 11 \u0e40\u0e1b\u0e47\u0e19 OUTPUT \npinMode(12, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 12 \u0e40\u0e1b\u0e47\u0e19 OUTPUT\npinMode(13, OUTPUT);//\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e32 13 \u0e40\u0e1b\u0e47\u0e19 OUTPUT \n\n\n}\n\nvoid loop() {\ndigitalWrite(13, HIGH); \ndigitalWrite(13, LOW); \ndigitalWrite(4, HIGH); \ndigitalWrite(4, LOW); \ndelay(300);\n\ndigitalWrite(12, HIGH); \ndigitalWrite(12, LOW); \ndigitalWrite(5, HIGH); \ndigitalWrite(5, LOW); \ndelay(300);\n\ndigitalWrite(11, HIGH); \ndigitalWrite(11, LOW); \ndigitalWrite(6, HIGH); \ndigitalWrite(6, LOW); \ndelay(300);\n\ndigitalWrite(10, HIGH); \ndigitalWrite(10, LOW); \ndigitalWrite(7, HIGH); \ndigitalWrite(7, LOW);\ndelay(300);\n\ndigitalWrite(9, HIGH); \ndigitalWrite(9, LOW); \ndigitalWrite(8, HIGH); \ndigitalWrite(8, LOW); \ndelay(300);\ndigitalWrite(9, HIGH); \ndigitalWrite(9, LOW); \ndigitalWrite(8, HIGH); \ndigitalWrite(8, LOW);\n\ndigitalWrite(10, HIGH); \ndigitalWrite(10, LOW); \ndigitalWrite(7, HIGH); \ndigitalWrite(7, LOW);\ndelay(300);\n\n\ndigitalWrite(11, HIGH); \ndigitalWrite(11, LOW); \ndigitalWrite(6, HIGH); \ndigitalWrite(6, LOW); \ndelay(300);\n\n\ndigitalWrite(12, HIGH); \ndigitalWrite(12, LOW); \ndigitalWrite(5, HIGH); \ndigitalWrite(5, LOW); \ndelay(300);\n\ndigitalWrite(13, HIGH); \ndigitalWrite(13, LOW); \ndigitalWrite(4, HIGH); \ndigitalWrite(4, LOW); \ndelay(300);\n\n}", + "output": "{\n \"version\": 1,\n \"author\": \"\u0e28\u0e38\u0e20\u0e0a\u0e31\u0e22 \u0e22\u0e32\u0e21\u0e35\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 183, \"left\": -0.6, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -42, \"left\": -140.2, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -42,\n \"left\": -53.8,\n \"attrs\": { \"color\": \"green\" }\n },\n { \"type\": \"wokwi-led\", \"id\": \"led3\", \"top\": -42, \"left\": 71, \"attrs\": { \"color\": \"yellow\" } },\n { \"type\": \"wokwi-led\", \"id\": \"led4\", \"top\": -42, \"left\": 13.4, \"attrs\": { \"color\": \"blue\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led5\",\n \"top\": -51.6,\n \"left\": 119,\n \"attrs\": { \"color\": \"orange\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led6\",\n \"top\": -42,\n \"left\": 224.6,\n \"attrs\": { \"color\": \"purple\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led7\",\n \"top\": -42,\n \"left\": 349.4,\n \"attrs\": { \"color\": \"limegreen\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led8\",\n \"top\": -42,\n \"left\": 176.6,\n \"attrs\": { \"color\": \"white\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led9\",\n \"top\": -42,\n \"left\": 282.2,\n \"attrs\": { \"color\": \"magenta\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led10\",\n \"top\": -42,\n \"left\": 397.4,\n \"attrs\": { \"color\": \"cyan\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 61,\n \"left\": -144.85,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 80.2,\n \"left\": 373.55,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 70.6,\n \"left\": 335.15,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r4\",\n \"top\": 51.4,\n \"left\": 277.55,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r5\",\n \"top\": 51.4,\n \"left\": 210.35,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r6\",\n \"top\": 41.8,\n \"left\": 171.95,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r7\",\n \"top\": 51.4,\n \"left\": 114.35,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r8\",\n \"top\": 61,\n \"left\": 66.35,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r9\",\n \"top\": 61,\n \"left\": 18.35,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r10\",\n \"top\": 70.6,\n \"left\": -58.45,\n \"rotate\": 270,\n \"attrs\": { \"value\": \"220000\" }\n }\n ],\n \"connections\": [\n [ \"led2:C\", \"uno:GND.1\", \"green\", [ \"v28.8\", \"h115.6\" ] ],\n [ \"led4:C\", \"uno:GND.1\", \"green\", [ \"v19.2\", \"h86.8\" ] ],\n [ \"led3:C\", \"uno:GND.1\", \"green\", [ \"v48\", \"h58\" ] ],\n [ \"led5:C\", \"uno:GND.1\", \"green\", [ \"v153.6\", \"h-19.1\" ] ],\n [ \"led8:C\", \"uno:GND.1\", \"green\", [ \"v153.6\", \"h-57.5\" ] ],\n [ \"led6:C\", \"uno:GND.1\", \"green\", [ \"v28.8\", \"h-28.4\" ] ],\n [ \"led9:C\", \"uno:GND.1\", \"green\", [ \"v38.4\", \"h-57.2\" ] ],\n [ \"led7:C\", \"uno:GND.1\", \"green\", [ \"v28.8\", \"h-86\" ] ],\n [ \"led10:C\", \"uno:GND.1\", \"green\", [ \"v48\", \"h-105.2\" ] ],\n [ \"led1:A\", \"r1:2\", \"green\", [ \"v0\" ] ],\n [ \"led2:A\", \"r10:2\", \"green\", [ \"v0\" ] ],\n [ \"led4:A\", \"r9:2\", \"green\", [ \"v0\" ] ],\n [ \"led3:A\", \"r8:2\", \"green\", [ \"v0\" ] ],\n [ \"led5:A\", \"r7:2\", \"green\", [ \"v0\" ] ],\n [ \"led8:A\", \"r6:2\", \"green\", [ \"v0\" ] ],\n [ \"led6:A\", \"r5:2\", \"green\", [ \"v0\" ] ],\n [ \"led9:A\", \"r4:2\", \"green\", [ \"v0\" ] ],\n [ \"led7:A\", \"r3:2\", \"green\", [ \"v0\" ] ],\n [ \"led10:A\", \"r2:2\", \"green\", [ \"v0\" ] ],\n [ \"led1:C\", \"uno:GND.1\", \"green\", [ \"v19.2\", \"h-18.8\", \"v134.4\", \"h144\" ] ],\n [ \"r1:1\", \"uno:13\", \"green\", [ \"h0\", \"v28.8\", \"h134.4\" ] ],\n [ \"r10:1\", \"uno:12\", \"green\", [ \"h0\", \"v38.4\", \"h105.6\" ] ],\n [ \"r9:1\", \"uno:11\", \"green\", [ \"h0\", \"v28.8\", \"h86.4\" ] ],\n [ \"r8:1\", \"uno:10\", \"green\", [ \"h0\", \"v38.4\", \"h67.2\" ] ],\n [ \"r7:1\", \"uno:9\", \"green\", [ \"h0\", \"v38.4\", \"h48\" ] ],\n [ \"r6:1\", \"uno:8\", \"green\", [ \"h9.6\", \"v38.4\", \"h19.2\" ] ],\n [ \"r5:1\", \"uno:7\", \"green\", [ \"h0\" ] ],\n [ \"r4:1\", \"uno:6\", \"green\", [ \"h0\" ] ],\n [ \"r3:1\", \"uno:5\", \"green\", [ \"h0\" ] ],\n [ \"r2:1\", \"uno:4\", \"green\", [ \"h0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for four road junction traffic light using arduino-uno", + "input": "int red1 = 13; \n int yellow1 = 12;\n int green1 = 11;\n int red2 = 10;\n int yellow2 = 9;\n int green2 = 8;\n int red3 =5;\n int yellow3 =6;\n int green3 = 7;\n int red4 =2;\n int yellow4=3;\n int green4=4 ;\n \nvoid setup() {\n // put your setup code here, to run once:\n//1\n pinMode(red1, OUTPUT);\n pinMode(yellow1, OUTPUT);\n pinMode(green1, OUTPUT);\n //2\n pinMode(red2, OUTPUT);\n pinMode(yellow2, OUTPUT);\n pinMode(green2, OUTPUT);\n //3\n pinMode(red3, OUTPUT);\n pinMode(yellow3, OUTPUT);\n pinMode(green3, OUTPUT);\n //4\n pinMode(red4, OUTPUT);\n pinMode(yellow4, OUTPUT);\n pinMode(green4, OUTPUT);\n}\n\nvoid loop() {\n // put your main code here, to run repeatedly:\n digitalWrite(green1, HIGH); \n digitalWrite(yellow1,LOW);\n digitalWrite(red1,LOW);\n delay(5000);\n digitalWrite(green1, LOW);\n digitalWrite(yellow1, HIGH);\n digitalWrite(red1,LOW);\n delay(2000);\n digitalWrite(green1, LOW);\ndigitalWrite(yellow1, LOW);\ndigitalWrite(red1,HIGH);\ndelay(3000);\n//2\ndigitalWrite(green2, HIGH); \n digitalWrite(yellow2,LOW);\n digitalWrite(red2,LOW);\n delay(5000);\n digitalWrite(green2, LOW);\n digitalWrite(yellow2, HIGH);\n digitalWrite(red2,LOW);\n delay(2000);\n digitalWrite(green2, LOW);\ndigitalWrite(yellow2, LOW);\ndigitalWrite(red2,HIGH);\ndelay(3000);\n//3\n digitalWrite(green3, HIGH); \n digitalWrite(yellow3,LOW);\n digitalWrite(red3,LOW);\n delay(5000);\n digitalWrite(green3, LOW);\n digitalWrite(yellow3, HIGH);\n digitalWrite(red3,LOW);\n delay(2000);\n digitalWrite(green3, LOW);\ndigitalWrite(yellow3, LOW);\ndigitalWrite(red3,HIGH);\ndelay(3000);\n//4\ndigitalWrite(green4, HIGH); \n digitalWrite(yellow4,LOW);\n digitalWrite(red4,LOW);\n delay(5000);\n digitalWrite(green3, LOW);\n digitalWrite(yellow4, HIGH);\n digitalWrite(red4,LOW);\n delay(2000);\n digitalWrite(green4, LOW);\ndigitalWrite(yellow4, LOW);\ndigitalWrite(red4,HIGH);\ndelay(3000);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Doungkmon Namyhong\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-mini\", \"id\": \"bb1\", \"top\": 104.2, \"left\": -472.8, \"attrs\": {} },\n { \"type\": \"wokwi-breadboard-mini\", \"id\": \"bb2\", \"top\": 469, \"left\": 36, \"attrs\": {} },\n { \"type\": \"wokwi-breadboard-mini\", \"id\": \"bb3\", \"top\": 104.2, \"left\": 439.2, \"attrs\": {} },\n { \"type\": \"wokwi-breadboard-mini\", \"id\": \"bb4\", \"top\": -203, \"left\": -12, \"attrs\": {} },\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 87, \"left\": -77.4, \"attrs\": {} },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led1\",\n \"top\": 82.8,\n \"left\": 493.4,\n \"attrs\": { \"color\": \"yellow\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": 447.6,\n \"left\": 99.8,\n \"attrs\": { \"color\": \"yellow\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": 447.6,\n \"left\": 128.6,\n \"attrs\": { \"color\": \"limegreen\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led4\",\n \"top\": 82.8,\n \"left\": -447.4,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led5\",\n \"top\": 82.8,\n \"left\": -418.6,\n \"attrs\": { \"color\": \"yellow\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led6\",\n \"top\": 82.8,\n \"left\": -389.8,\n \"attrs\": { \"color\": \"limegreen\" }\n },\n { \"type\": \"wokwi-led\", \"id\": \"led7\", \"top\": -224.4, \"left\": 23, \"attrs\": { \"color\": \"red\" } },\n { \"type\": \"wokwi-led\", \"id\": \"led8\", \"top\": 447.6, \"left\": 71, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led9\",\n \"top\": -224.4,\n \"left\": 51.8,\n \"attrs\": { \"color\": \"yellow\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led10\",\n \"top\": -224.4,\n \"left\": 80.6,\n \"attrs\": { \"color\": \"limegreen\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led11\",\n \"top\": 82.8,\n \"left\": 531.8,\n \"attrs\": { \"color\": \"limegreen\" }\n },\n { \"type\": \"wokwi-led\", \"id\": \"led12\", \"top\": 82.8, \"left\": 455, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 148.8,\n \"left\": -451.75,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r2\",\n \"top\": 148.8,\n \"left\": -422.95,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r3\",\n \"top\": 148.8,\n \"left\": -394.15,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r4\",\n \"top\": 513.6,\n \"left\": 124.25,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r5\",\n \"top\": 513.6,\n \"left\": 66.65,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r6\",\n \"top\": 513.6,\n \"left\": 95.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r7\",\n \"top\": 148.8,\n \"left\": 450.65,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r8\",\n \"top\": 148.8,\n \"left\": 489.05,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r9\",\n \"top\": 148.8,\n \"left\": 527.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r10\",\n \"top\": -158.4,\n \"left\": 76.25,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r11\",\n \"top\": -158.4,\n \"left\": 47.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r12\",\n \"top\": -158.4,\n \"left\": 18.65,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n }\n ],\n \"connections\": [\n [ \"uno:13\", \"r7:2\", \"red\", [ \"v-86.4\", \"h-66.8\" ] ],\n [ \"uno:12\", \"r8:2\", \"gold\", [ \"v-96\", \"h-37.9\" ] ],\n [ \"uno:11\", \"r9:2\", \"green\", [ \"v-96\", \"h-9\" ] ],\n [ \"uno:10\", \"r5:2\", \"red\", [ \"v-48\", \"h192.7\", \"v192\", \"h134.4\" ] ],\n [ \"uno:9\", \"r6:2\", \"gold\", [ \"v-28.8\", \"h173.6\", \"v192\", \"h182.4\" ] ],\n [ \"uno:8\", \"r4:2\", \"green\", [ \"v-19.2\", \"h144.4\", \"v192\", \"h230.4\" ] ],\n [ \"uno:5\", \"r1:2\", \"red\", [ \"v278.4\", \"h90.2\", \"v220.8\", \"h-192\" ] ],\n [ \"uno:6\", \"bb1:8b.g\", \"gold\", [ \"v288\", \"h90.1\", \"v201.6\", \"h-163.2\" ] ],\n [ \"bb1:8b.g\", \"r2:2\", \"gold\", [ \"v0\" ] ],\n [ \"uno:7\", \"r3:2\", \"green\", [ \"v297.6\", \"h90\", \"v172.8\", \"h-124.8\" ] ],\n [ \"uno:2\", \"r12:2\", \"red\", [ \"v-19.2\", \"h-351.1\", \"v182.4\", \"h-172.8\" ] ],\n [ \"uno:3\", \"r11:2\", \"gold\", [ \"v-38.4\", \"h-360.8\", \"v192\", \"h-124.8\" ] ],\n [ \"uno:4\", \"r10:2\", \"green\", [ \"v-57.6\", \"h-370.5\", \"v201.6\", \"h-76.8\" ] ],\n [ \"uno:GND.1\", \"led12:C\", \"black\", [ \"v-76.8\", \"h-66.9\" ] ],\n [ \"uno:GND.1\", \"led1:C\", \"black\", [ \"v-76.8\", \"h-28.5\" ] ],\n [ \"uno:GND.1\", \"led11:C\", \"black\", [ \"v-76.8\", \"h19.5\" ] ],\n [ \"uno:GND.1\", \"led8:C\", \"black\", [ \"v-67.2\", \"h240.3\", \"v201.6\", \"h115.2\" ] ],\n [ \"uno:GND.1\", \"led2:C\", \"black\", [ \"v-67.2\", \"h240.3\", \"v201.6\", \"h144\" ] ],\n [ \"uno:GND.1\", \"led3:C\", \"black\", [ \"v-67.2\", \"h240.3\", \"v201.6\", \"h172.8\" ] ],\n [ \"uno:GND.1\", \"led4:C\", \"black\", [ \"v278.4\", \"h-18.9\" ] ],\n [ \"uno:GND.1\", \"led5:C\", \"black\", [ \"v259.2\", \"h-441.7\" ] ],\n [ \"uno:GND.1\", \"led6:C\", \"black\", [ \"v288\", \"h38.7\" ] ],\n [ \"uno:GND.1\", \"led7:C\", \"black\", [ \"v-57.6\", \"h-412.5\" ] ],\n [ \"uno:GND.1\", \"led9:C\", \"black\", [ \"v-57.6\", \"h-383.7\" ] ],\n [ \"uno:GND.1\", \"led10:C\", \"black\", [ \"v-57.6\", \"h-345.3\" ] ],\n [ \"led1:A\", \"bb3:8t.b\", \"\", [ \"$bb\" ] ],\n [ \"led1:C\", \"bb3:7t.b\", \"\", [ \"$bb\" ] ],\n [ \"led11:A\", \"bb3:12t.b\", \"\", [ \"$bb\" ] ],\n [ \"led11:C\", \"bb3:11t.b\", \"\", [ \"$bb\" ] ],\n [ \"led12:A\", \"bb3:4t.b\", \"\", [ \"$bb\" ] ],\n [ \"led12:C\", \"bb3:3t.b\", \"\", [ \"$bb\" ] ],\n [ \"r7:1\", \"bb3:4t.b\", \"\", [ \"$bb\" ] ],\n [ \"r7:2\", \"bb3:4b.f\", \"\", [ \"$bb\" ] ],\n [ \"r8:1\", \"bb3:8t.b\", \"\", [ \"$bb\" ] ],\n [ \"r8:2\", \"bb3:8b.f\", \"\", [ \"$bb\" ] ],\n [ \"r9:1\", \"bb3:12t.b\", \"\", [ \"$bb\" ] ],\n [ \"r9:2\", \"bb3:12b.f\", \"\", [ \"$bb\" ] ],\n [ \"led2:A\", \"bb2:9t.b\", \"\", [ \"$bb\" ] ],\n [ \"led2:C\", \"bb2:8t.b\", \"\", [ \"$bb\" ] ],\n [ \"led3:A\", \"bb2:12t.b\", \"\", [ \"$bb\" ] ],\n [ \"led3:C\", \"bb2:11t.b\", \"\", [ \"$bb\" ] ],\n [ \"led8:A\", \"bb2:6t.b\", \"\", [ \"$bb\" ] ],\n [ \"led8:C\", \"bb2:5t.b\", \"\", [ \"$bb\" ] ],\n [ \"r4:1\", \"bb2:12t.b\", \"\", [ \"$bb\" ] ],\n [ \"r4:2\", \"bb2:12b.f\", \"\", [ \"$bb\" ] ],\n [ \"r5:1\", \"bb2:6t.b\", \"\", [ \"$bb\" ] ],\n [ \"r5:2\", \"bb2:6b.f\", \"\", [ \"$bb\" ] ],\n [ \"r6:1\", \"bb2:9t.b\", \"\", [ \"$bb\" ] ],\n [ \"r6:2\", \"bb2:9b.f\", \"\", [ \"$bb\" ] ],\n [ \"led7:A\", \"bb4:6t.b\", \"\", [ \"$bb\" ] ],\n [ \"led7:C\", \"bb4:5t.b\", \"\", [ \"$bb\" ] ],\n [ \"led9:A\", \"bb4:9t.b\", \"\", [ \"$bb\" ] ],\n [ \"led9:C\", \"bb4:8t.b\", \"\", [ \"$bb\" ] ],\n [ \"led10:A\", \"bb4:12t.b\", \"\", [ \"$bb\" ] ],\n [ \"led10:C\", \"bb4:11t.b\", \"\", [ \"$bb\" ] ],\n [ \"r10:1\", \"bb4:12t.b\", \"\", [ \"$bb\" ] ],\n [ \"r10:2\", \"bb4:12b.f\", \"\", [ \"$bb\" ] ],\n [ \"r11:1\", \"bb4:9t.b\", \"\", [ \"$bb\" ] ],\n [ \"r11:2\", \"bb4:9b.f\", \"\", [ \"$bb\" ] ],\n [ \"r12:1\", \"bb4:6t.b\", \"\", [ \"$bb\" ] ],\n [ \"r12:2\", \"bb4:6b.f\", \"\", [ \"$bb\" ] ],\n [ \"led4:A\", \"bb1:5t.b\", \"\", [ \"$bb\" ] ],\n [ \"led4:C\", \"bb1:4t.b\", \"\", [ \"$bb\" ] ],\n [ \"led5:A\", \"bb1:8t.b\", \"\", [ \"$bb\" ] ],\n [ \"led5:C\", \"bb1:7t.b\", \"\", [ \"$bb\" ] ],\n [ \"led6:A\", \"bb1:11t.b\", \"\", [ \"$bb\" ] ],\n [ \"led6:C\", \"bb1:10t.b\", \"\", [ \"$bb\" ] ],\n [ \"r1:1\", \"bb1:5t.b\", \"\", [ \"$bb\" ] ],\n [ \"r1:2\", \"bb1:5b.f\", \"\", [ \"$bb\" ] ],\n [ \"r2:1\", \"bb1:8t.b\", \"\", [ \"$bb\" ] ],\n [ \"r2:2\", \"bb1:8b.f\", \"\", [ \"$bb\" ] ],\n [ \"r3:1\", \"bb1:11t.b\", \"\", [ \"$bb\" ] ],\n [ \"r3:2\", \"bb1:11b.f\", \"\", [ \"$bb\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for motion detection alarm using PIR sensor,esp-32,buzzer", + "input": "#include \n\nconst int pirPin = 14; // PIR Motion Sensor connected to GPIO 14\nconst int buzzerPin = 13; // Buzzer connected to GPIO 13\n\nvoid setup() {\n pinMode(pirPin, INPUT);\n pinMode(buzzerPin, OUTPUT);\n Serial.begin(115200);\n}\n\nvoid loop() {\n int pirState = digitalRead(pirPin);\n if (pirState == HIGH) {\n Serial.println(\"Motion Detected!\");\n tone(buzzerPin, 1000, 500); // Sound the buzzer for 500 milliseconds\n } else {\n noTone(buzzerPin);\n }\n delay(1000); // Delay for 1 second to avoid false triggers\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-mini\", \"id\": \"bb1\", \"top\": 94.6, \"left\": 122.4, \"attrs\": {} },\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 9.6, \"left\": -23.96, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -45.6,\n \"left\": 117,\n \"attrs\": { \"volume\": \"0.1\" }\n },\n {\n \"type\": \"wokwi-pir-motion-sensor\",\n \"id\": \"pir1\",\n \"top\": -15.2,\n \"left\": -180.18,\n \"attrs\": {}\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"bz1:2\", \"esp:13\", \"green\", [ \"v0\" ] ],\n [ \"bz1:1\", \"bb1:1t.d\", \"black\", [ \"v0\" ] ],\n [ \"pir1:VCC\", \"esp:3V3\", \"red\", [ \"v0\" ] ],\n [ \"pir1:GND\", \"bb1:1t.c\", \"black\", [ \"v0\" ] ],\n [ \"pir1:OUT\", \"esp:14\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for water level indicator using arduino-uno", + "input": "const int sensorPin = A0;\nconst int ledPins[] = {2, 3, 4, 5, 6};\nconst int numLeds = 5;\n\nvoid setup() {\n for (int i = 0; i < numLeds; i++) {\n pinMode(ledPins[i], OUTPUT);\n }\n Serial.begin(9600);\n}\n\nvoid loop() {\n int sensorValue = analogRead(sensorPin);\n int ledValue = map(sensorValue, 0, 1023, 0, numLeds);\n \n for (int i = 0; i < numLeds; i++) {\n digitalWrite(ledPins[i], i < ledValue ? HIGH : LOW);\n }\n \n Serial.println(sensorValue);\n delay(1000);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Anonymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-half\", \"id\": \"bb1\", \"top\": -41.4, \"left\": -64.4, \"attrs\": {} },\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 125.4, \"left\": -48.6, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -51.6, \"left\": 61.4, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -51.6,\n \"left\": 90.2,\n \"attrs\": { \"color\": \"orange\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": -51.6,\n \"left\": 119,\n \"attrs\": { \"color\": \"green\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led4\",\n \"top\": -51.6,\n \"left\": 176.6,\n \"attrs\": { \"color\": \"white\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led5\",\n \"top\": -51.6,\n \"left\": 147.8,\n \"attrs\": { \"color\": \"cyan\" }\n },\n { \"type\": \"chip-water-level-sensor\", \"id\": \"chip1\", \"top\": 356.22, \"left\": 33.6, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"led4:A\", \"uno:2\", \"green\", [ \"v67.2\", \"h-13.7\" ] ],\n [ \"led5:A\", \"uno:3\", \"green\", [ \"h9.6\", \"v144\" ] ],\n [ \"led3:A\", \"uno:4\", \"green\", [ \"v76.8\", \"h24.9\" ] ],\n [ \"led2:A\", \"uno:5\", \"green\", [ \"v86.4\", \"h9.6\" ] ],\n [ \"led1:A\", \"uno:6\", \"green\", [ \"v96\", \"h9.6\" ] ],\n [ \"led1:C\", \"bb1:4t.a\", \"black\", [ \"v0\" ] ],\n [ \"led2:C\", \"bb1:4t.b\", \"black\", [ \"v0\" ] ],\n [ \"led3:C\", \"bb1:4t.c\", \"black\", [ \"v0\" ] ],\n [ \"led5:C\", \"bb1:4t.d\", \"black\", [ \"v0\" ] ],\n [ \"led4:C\", \"bb1:4t.e\", \"black\", [ \"v0\" ] ],\n [ \"bb1:4t.e\", \"uno:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"chip1:VCC\", \"uno:5V\", \"red\", [ \"h0\" ] ],\n [ \"chip1:GND\", \"uno:GND.2\", \"black\", [ \"h0\" ] ],\n [ \"chip1:OUT\", \"uno:A0\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}\n{\n \"name\": \"water-level-sensor\",\n \"author\": \"\",\n \"pins\": [\n \"VCC\",\n \"GND\",\n \"OUT\"\n ],\n \"controls\": []\n}" + }, + { + "instruction": "Generate a diagram.json code for Flame Detection System using IR Sensor, Buzzer, Arduino Nano", + "input": "const int flameSensorPin = 2;\nconst int buzzerPin = 3;\n\nvoid setup() {\n pinMode(flameSensorPin, INPUT);\n pinMode(buzzerPin, OUTPUT);\n Serial.begin(9600);\n}\n\nvoid loop() {\n int flameValue = digitalRead(flameSensorPin);\n if (flameValue == HIGH) {\n Serial.println(\"Flame detected!\");\n tone(buzzerPin, 1000, 500); // Sound the buzzer for 500 milliseconds\n } else {\n Serial.println(\"No flame detected.\");\n }\n delay(1000); // Check every second\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-nano\", \"id\": \"nano\", \"top\": -4.8, \"left\": -0.5, \"attrs\": {} },\n { \"type\": \"wokwi-ir-receiver\", \"id\": \"ir1\", \"top\": -106.95, \"left\": 27.02, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": 50.4,\n \"left\": 136.2,\n \"attrs\": { \"volume\": \"0.1\" }\n }\n ],\n \"connections\": [\n [ \"ir1:VCC\", \"nano:5V\", \"red\", [ \"v0\" ] ],\n [ \"ir1:GND\", \"nano:GND.1\", \"black\", [ \"v96\", \"h96\" ] ],\n [ \"ir1:DAT\", \"nano:2\", \"green\", [ \"h57.6\", \"v24\" ] ],\n [ \"bz1:1\", \"nano:GND.2\", \"black\", [ \"h-28.8\", \"v-153.6\" ] ],\n [ \"bz1:2\", \"nano:3\", \"yellow\", [ \"v19.2\", \"h-58\", \"v-153.6\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Sound reactive LED ring", + "input": "#include \n\n#define PIN 6 // Pin connected to the Data In of the NeoPixel ring\n#define NUMPIXELS 16 // Number of LEDs in the ring\n#define SOUND_SENSOR A0 // Analog pin connected to the sound sensor\n\nAdafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);\n\nvoid setup() {\n pixels.begin(); // Initialize the NeoPixel library\n Serial.begin(9600);\n}\n\nvoid loop() {\n int soundLevel = analogRead(SOUND_SENSOR); // Read the sound level from the sensor\n int brightness = map(soundLevel, 0, 1023, 0, 255); // Map the sound level to a brightness value\n\n // Set the brightness for each LED in the ring\n for (int i = 0; i < NUMPIXELS; i++) {\n pixels.setPixelColor(i, pixels.Color(0, 0, brightness)); // Blue color, adjust RGB values as needed\n }\n pixels.show(); // Update the LEDs to show the new colors\n\n Serial.println(soundLevel); // Print the sound level to the Serial Monitor\n delay(50); // Small delay to avoid rapid changes\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-nano\", \"id\": \"nano\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n {\n \"type\": \"wokwi-small-sound-sensor\",\n \"id\": \"\",\n \"top\": -107,\n \"left\": 48,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring1\",\n \"top\": 77.44,\n \"left\": 20.39,\n \"attrs\": { \"pixels\": \"16\" }\n }\n ],\n \"connections\": [\n [ \":DOUT\", \"nano:5V\", \"red\", [ \"v28.1\", \"h67.2\", \"v100.8\" ] ],\n [ \":GND\", \"nano:GND.2\", \"black\", [ \"h0\" ] ],\n [ \":AOUT\", \"nano:A0\", \"green\", [ \"h-9.6\", \"v76.8\", \"h10.1\" ] ],\n [ \"ring1:GND\", \"nano:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"ring1:VCC\", \"nano:5V\", \"red\", [ \"v0\" ] ],\n [ \"ring1:DIN\", \"nano:6\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Keypad Door Lock using arduino-uno,servo and membrane-keypad", + "input": "include \n#include \nconst byte ROWS = 4; // Four rows\nconst byte COLS = 4; // Four columns\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] = {2, 3, 4, 5}; // Connect to the row pinouts of the keypad\nbyte colPins[COLS] = {6, 7, 8, 9}; // Connect to the column pinouts of the keypad\nKeypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);\nServo myServo;\nconst String password = \"1234\";\nString inputPassword;\nvoid setup() {\n Serial.begin(9600);\n myServo.attach(10); // Servo connected to pin D10\n myServo.write(0); // Lock position\n Serial.println(\"Enter Password:\");\n}\nvoid loop() {\n char key = keypad.getKey();\n if (key) {\n Serial.print(key);\n if (key == '#') {\n if (inputPassword == password) {\n Serial.println(\"\\nAccess Granted\");\n myServo.write(90); // Unlock position\n delay(5000); // Keep the door unlocked for 5 seconds\n myServo.write(0); // Lock position\n } else {\n Serial.println(\"\\nAccess Denied\");\n }\n inputPassword = \"\"; // Clear the input password\n } else {\n inputPassword += key; // Append the key to the input password\n }\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 115.8, \"left\": -10.2, \"attrs\": {} },\n { \"type\": \"wokwi-membrane-keypad\", \"id\": \"keypad1\", \"top\": -309.2, \"left\": 34.4, \"attrs\": {} },\n { \"type\": \"wokwi-servo\", \"id\": \"servo1\", \"top\": 26.8, \"left\": -201.6, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"keypad1:R1\", \"uno:2\", \"green\", [ \"v57.6\", \"h96\" ] ],\n [ \"keypad1:R2\", \"uno:3\", \"green\", [ \"v67.2\", \"h76.4\" ] ],\n [ \"keypad1:R3\", \"uno:4\", \"green\", [ \"v76.8\", \"h57.3\" ] ],\n [ \"keypad1:R4\", \"uno:5\", \"green\", [ \"v86.4\", \"h28.6\" ] ],\n [ \"keypad1:C1\", \"uno:6\", \"green\", [ \"v0\" ] ],\n [ \"keypad1:C2\", \"uno:7\", \"green\", [ \"v0\" ] ],\n [ \"keypad1:C3\", \"uno:8\", \"green\", [ \"v0\" ] ],\n [ \"keypad1:C4\", \"uno:9\", \"green\", [ \"v0\" ] ],\n [ \"servo1:GND\", \"uno:GND.2\", \"black\", [ \"h-67.2\", \"v230.5\" ] ],\n [ \"servo1:V+\", \"uno:5V\", \"red\", [ \"h-48\", \"v57.5\", \"h399.4\" ] ],\n [ \"servo1:PWM\", \"uno:10\", \"orange\", [ \"h-19.2\", \"v67.4\", \"h345.6\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Temperature data logger using dht-22,arduino-mega,micro-sd-card", + "input": "#include \n#include \n#include \n\n// DHT22 Pin\n#define DHTPIN 2\ndht DHT;\n\n// SD Card Module CS Pin\n#define SD_CS_PIN 53\n\nvoid setup() {\n Serial.begin(9600);\n DHT.begin();\n if (!SD.begin(SD_CS_PIN)) {\n Serial.println(\"SD Card initialization failed!\");\n return;\n }\n Serial.println(\"SD Card initialized successfully!\");\n}\n\nvoid loop() {\n delay(2000); // Read every 2 seconds\n float humidity = DHT.readHumidity();\n float temperature = DHT.readTemperature();\n\n if (isnan(humidity) || isnan(temperature)) {\n Serial.println(\"Failed to read from DHT sensor!\");\n return;\n }\n\n String dataString = String(humidity) + \",\" + String(temperature);\n File dataFile = SD.open(\"datalog.txt\", FILE_WRITE);\n if (dataFile) {\n dataFile.println(dataString);\n dataFile.close();\n Serial.println(\"Data logged to SD card!\");\n } else {\n Serial.println(\"Error opening datalog.txt\");\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-mega\", \"id\": \"mega\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"wokwi-dht22\", \"id\": \"dht1\", \"top\": -143.7, \"left\": 186.6, \"attrs\": {} },\n { \"type\": \"wokwi-microsd-card\", \"id\": \"sd1\", \"top\": -114.97, \"left\": 9.67, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"dht1:VCC\", \"mega:5V\", \"red\", [ \"v163.2\", \"h-38.4\" ] ],\n [ \"dht1:GND\", \"mega:GND.2\", \"black\", [ \"v182.4\", \"h-57.6\" ] ],\n [ \"dht1:SDA\", \"mega:2\", \"green\", [ \"v0\" ] ],\n [ \"sd1:VCC\", \"mega:5V\", \"red\", [ \"h0\" ] ],\n [ \"sd1:GND\", \"mega:GND.3\", \"black\", [ \"h0\" ] ],\n [ \"sd1:DO\", \"mega:50\", \"green\", [ \"h0\" ] ],\n [ \"sd1:DI\", \"mega:51\", \"green\", [ \"h0\" ] ],\n [ \"sd1:CS\", \"mega:53\", \"green\", [ \"h307.2\", \"v211.26\" ] ],\n [ \"sd1:CD\", \"mega:GND.3\", \"green\", [ \"h57.6\", \"v326.4\", \"h38.4\" ] ],\n [ \"sd1:SCK\", \"mega:52\", \"green\", [ \"h259.2\", \"v239.99\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Remote controlled RGB LED", + "input": "#include \n\nconst int IR_PIN = 14;\nconst int RED_PIN = 2;\nconst int GREEN_PIN = 3;\nconst int BLUE_PIN = 4;\n\nIRrecv irrecv(IR_PIN);\ndecode_results results;\n\nvoid setup() {\n irrecv.enableIRIn(); // Start the receiver\n pinMode(RED_PIN, OUTPUT);\n pinMode(GREEN_PIN, OUTPUT);\n pinMode(BLUE_PIN, OUTPUT);\n}\n\nvoid loop() {\n if (irrecv.decode(&results)) {\n switch (results.value) {\n case 0xFF30CF:\n digitalWrite(RED_PIN, HIGH);\n digitalWrite(GREEN_PIN, LOW);\n digitalWrite(BLUE_PIN, LOW);\n break;\n case 0xFF18E7:\n digitalWrite(RED_PIN, LOW);\n digitalWrite(GREEN_PIN, HIGH);\n digitalWrite(BLUE_PIN, LOW);\n break;\n case 0xFF7A85:\n digitalWrite(RED_PIN, LOW);\n digitalWrite(GREEN_PIN, LOW);\n digitalWrite(BLUE_PIN, HIGH);\n break;\n default:\n digitalWrite(RED_PIN, LOW);\n digitalWrite(GREEN_PIN, LOW);\n digitalWrite(BLUE_PIN, LOW);\n break;\n }\n irrecv.resume(); // Receive the next value\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": -19.2, \"left\": 120.04, \"attrs\": {} },\n { \"type\": \"wokwi-ir-receiver\", \"id\": \"ir1\", \"top\": -68.55, \"left\": -1.78, \"attrs\": {} },\n { \"type\": \"wokwi-ir-remote\", \"id\": \"remote1\", \"top\": 105.6, \"left\": -192, \"attrs\": {} },\n {\n \"type\": \"wokwi-rgb-led\",\n \"id\": \"rgb1\",\n \"top\": -120.8,\n \"left\": 106.7,\n \"attrs\": { \"common\": \"cathode\" }\n },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 81.6,\n \"left\": 57.05,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"r1:1\", \"rgb1:COM\", \"black\", [ \"h0\", \"v-163.2\" ] ],\n [ \"r1:2\", \"esp:GND.1\", \"black\", [ \"h0\", \"v18\" ] ],\n [ \"rgb1:G\", \"esp:D3\", \"green\", [ \"v0\" ] ],\n [ \"rgb1:R\", \"esp:D2\", \"red\", [ \"v0\" ] ],\n [ \"rgb1:B\", \"esp:4\", \"blue\", [ \"v0\" ] ],\n [ \"ir1:VCC\", \"esp:3V3\", \"red\", [ \"v0\" ] ],\n [ \"ir1:GND\", \"esp:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"ir1:DAT\", \"esp:14\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Tilt sensor alarm usng esp-32", + "input": "#include \n\nconst int tiltSensorPin = 4; // GPIO pin connected to the tilt switch\nconst int buzzerPin = 13; // GPIO pin connected to the buzzer\n\nvoid setup() {\n pinMode(tiltSensorPin, INPUT_PULLUP); // Set tilt switch pin as input with pull-up resistor\n pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output\n Serial.begin(115200);\n}\n\nvoid loop() {\n int sensorValue = digitalRead(tiltSensorPin);\n \n if (sensorValue == HIGH) {\n // Tilt detected, turn on buzzer\n digitalWrite(buzzerPin, HIGH);\n Serial.println(\"Tilt detected! Buzzer ON.\");\n } else {\n // No tilt, turn off buzzer\n digitalWrite(buzzerPin, LOW);\n Serial.println(\"No tilt detected. Buzzer OFF.\");\n }\n \n delay(100); // Short delay to avoid rapid changes\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Ananoymous maker\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -64.8,\n \"left\": -123,\n \"attrs\": { \"volume\": \"0.1\" }\n },\n {\n \"type\": \"wokwi-tilt-switch\",\n \"id\": \"btn1\",\n \"top\": -114,\n \"left\": -11.2,\n \"attrs\": { \"color\": \"green\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"bz1:2\", \"esp:13\", \"red\", [ \"v0\" ] ],\n [ \"bz1:1\", \"esp:GND.1\", \"black\", [ \"v134.4\", \"h96\" ] ],\n [ \"btn1:GND\", \"esp:GND.3\", \"black\", [ \"h38.4\", \"v182.4\" ] ],\n [ \"btn1:VCC\", \"esp:3V3\", \"red\", [ \"h19.2\", \"v76.6\", \"h-105.6\", \"v38.4\" ] ],\n [ \"btn1:OUT\", \"esp:4\", \"green\", [ \"h48\", \"v220.5\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Digital Voltmeter", + "input": "#include \n#include \n\n#define POT_PIN A0\nLiquidCrystal_I2C lcd(0x27, 16, 2); // Change 0x27 to your LCD I2C address\n\nvoid setup() {\n lcd.begin();\n lcd.print(\"Voltmeter\");\n}\n\nvoid loop() {\n int sensorValue = analogRead(POT_PIN);\n float voltage = sensorValue * (5.0 / 1023.0);\n \n lcd.setCursor(0, 1);\n lcd.print(\"Voltage: \");\n lcd.print(voltage);\n lcd.print(\" V\");\n\n delay(500);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0.6, \"left\": -0.6, \"attrs\": {} },\n { \"type\": \"wokwi-potentiometer\", \"id\": \"pot1\", \"top\": -116.5, \"left\": 86.2, \"attrs\": {} },\n {\n \"type\": \"wokwi-lcd1602\",\n \"id\": \"lcd1\",\n \"top\": 217.6,\n \"left\": -13.6,\n \"attrs\": { \"pins\": \"i2c\" }\n }\n ],\n \"connections\": [\n [ \"pot1:VCC\", \"uno:5V\", \"red\", [ \"v57.6\", \"h162.4\", \"v220.8\", \"h-124.8\" ] ],\n [ \"pot1:GND\", \"uno:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"pot1:SIG\", \"uno:A0\", \"orange\", [ \"v163.2\", \"h76.4\" ] ],\n [ \"lcd1:GND\", \"uno:GND.2\", \"black\", [ \"h-9.6\", \"v-38.4\", \"h192\" ] ],\n [ \"lcd1:VCC\", \"uno:5V\", \"red\", [ \"h-28.8\", \"v-38.3\", \"h201.6\" ] ],\n [ \"lcd1:SDA\", \"uno:A4\", \"magenta\", [ \"h-38.4\", \"v57.8\", \"h355.2\" ] ],\n [ \"lcd1:SCL\", \"uno:A5\", \"white\", [ \"h-28.8\", \"v86.7\", \"h364.8\", \"v-163.2\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Analog joy stick control using arduino-mega", + "input": "#include \n\n#define PIN 6 // Pin connected to the Data In of the NeoPixel ring\n#define NUMPIXELS 16 // Number of LEDs in the ring\n#define JOYSTICK_X A0 // Analog pin connected to the joystick's VRx\n#define JOYSTICK_Y A1 // Analog pin connected to the joystick's VRy\n#define JOYSTICK_SW 2 // Digital pin connected to the joystick's switch\n\nAdafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);\n\nvoid setup() {\n pixels.begin(); // Initialize the NeoPixel library\n pinMode(JOYSTICK_SW, INPUT_PULLUP); // Set the switch pin as input with pull-up resistor\n Serial.begin(9600);\n}\n\nvoid loop() {\n int xValue = analogRead(JOYSTICK_X); // Read the horizontal value\n int yValue = analogRead(JOYSTICK_Y); // Read the vertical value\n int swValue = digitalRead(JOYSTICK_SW); // Read the switch value\n\n // Map the joystick values to the number of LEDs\n int xMapped = map(xValue, 0, 1023, 0, NUMPIXELS);\n int yMapped = map(yValue, 0, 1023, 0, NUMPIXELS);\n\n // Set the color of the LEDs based on the joystick position\n for (int i = 0; i < NUMPIXELS; i++) {\n if (i == xMapped || i == yMapped) {\n pixels.setPixelColor(i, pixels.Color(255, 0, 0)); // Set the color to red\n } else {\n pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Turn off the other LEDs\n }\n }\n\n pixels.show(); // Update the LEDs\n\n Serial.print(\"X: \");\n Serial.print(xValue);\n Serial.print(\" Y: \");\n Serial.print(yValue);\n Serial.print(\" SW: \");\n Serial.println(swValue);\n\n delay(100); // Short delay to avoid rapid changes\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-mega\", \"id\": \"mega\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n {\n \"type\": \"wokwi-analog-joystick\",\n \"id\": \"joystick1\",\n \"top\": -173.4,\n \"left\": 168.6,\n \"attrs\": {}\n },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring1\",\n \"top\": -162.56,\n \"left\": -162.01,\n \"attrs\": { \"pixels\": \"16\" }\n }\n ],\n \"connections\": [\n [ \"joystick1:VCC\", \"mega:5V\", \"red\", [ \"v48\", \"h-37.1\" ] ],\n [ \"joystick1:GND\", \"mega:GND.2\", \"black\", [ \"v115.2\", \"h-57.6\", \"v134.4\" ] ],\n [ \"joystick1:HORZ\", \"mega:A0\", \"white\", [ \"v0\" ] ],\n [ \"joystick1:VERT\", \"mega:A1\", \"cyan\", [ \"v0\" ] ],\n [ \"joystick1:SEL\", \"mega:2\", \"green\", [ \"v0\" ] ],\n [ \"ring1:GND\", \"mega:GND.3\", \"black\", [ \"v220.8\", \"h288\" ] ],\n [ \"ring1:VCC\", \"mega:5V\", \"red\", [ \"v211.2\", \"h259.2\" ] ],\n [ \"ring1:DIN\", \"mega:6\", \"green\", [ \"v-9.6\", \"h288\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Digital thermometer using DHT-22 and arduino-uno", + "input": "#include \n#include \n#include \n\n#define DHTPIN 2\n#define DHTTYPE DHT22\nDHT dht(DHTPIN, DHTTYPE);\nLiquidCrystal_I2C lcd(0x27, 16, 2); // Change 0x27 to your LCD I2C address\n\nvoid setup() {\n lcd.begin();\n dht.begin();\n lcd.print(\"Temp:\");\n}\n\nvoid loop() {\n float temp = dht.readTemperature();\n lcd.setCursor(6, 0);\n lcd.print(temp);\n lcd.print(\" C\");\n delay(2000);\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 77.4, \"left\": -106.2, \"attrs\": {} },\n { \"type\": \"wokwi-dht22\", \"id\": \"dht1\", \"top\": -114.9, \"left\": -24.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-lcd1602\",\n \"id\": \"lcd1\",\n \"top\": -108.8,\n \"left\": 82.4,\n \"attrs\": { \"pins\": \"i2c\" }\n }\n ],\n \"connections\": [\n [ \"dht1:VCC\", \"uno:5V\", \"red\", [ \"v297.6\", \"h57.6\" ] ],\n [ \"dht1:GND\", \"uno:GND.2\", \"black\", [ \"v307.2\", \"h48\" ] ],\n [ \"dht1:SDA\", \"uno:2\", \"green\", [ \"v67.2\", \"h124.9\" ] ],\n [ \"lcd1:GND\", \"uno:GND.3\", \"black\", [ \"h0\" ] ],\n [ \"lcd1:VCC\", \"uno:5V\", \"red\", [ \"h0\" ] ],\n [ \"lcd1:SDA\", \"uno:A4\", \"green\", [ \"h0\" ] ],\n [ \"lcd1:SCL\", \"uno:A5\", \"green\", [ \"h0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for LED Chaser using Arduino-mega", + "input": "const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};\nconst int numLeds = sizeof(ledPins) / sizeof(ledPins[0]);\n\nvoid setup() {\n for (int i = 0; i < numLeds; i++) {\n pinMode(ledPins[i], OUTPUT);\n }\n}\n\nvoid loop() {\n for (int i = 0; i < numLeds; i++) {\n digitalWrite(ledPins[i], HIGH);\n delay(100); // Adjust delay to change the speed of the chaser\n digitalWrite(ledPins[i], LOW);\n }\n}", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-breadboard-mini\", \"id\": \"bb1\", \"top\": -135.8, \"left\": 352.8, \"attrs\": {} },\n { \"type\": \"wokwi-arduino-mega\", \"id\": \"mega\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -109.2, \"left\": 71, \"attrs\": { \"color\": \"red\" } },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led2\",\n \"top\": -109.2,\n \"left\": 109.4,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led3\",\n \"top\": -109.2,\n \"left\": 147.8,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led4\",\n \"top\": -109.2,\n \"left\": 186.2,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led5\",\n \"top\": -109.2,\n \"left\": 224.6,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-led\",\n \"id\": \"led6\",\n \"top\": -109.2,\n \"left\": 253.4,\n \"attrs\": { \"color\": \"red\" }\n }\n ],\n \"connections\": [\n [ \"led6:A\", \"mega:2\", \"green\", [ \"v0\" ] ],\n [ \"led4:A\", \"mega:4\", \"green\", [ \"v57.6\", \"h9.6\" ] ],\n [ \"led3:A\", \"mega:5\", \"green\", [ \"v57.6\", \"h28.8\" ] ],\n [ \"led2:A\", \"mega:6\", \"green\", [ \"v67.2\", \"h67.2\" ] ],\n [ \"led1:A\", \"mega:7\", \"green\", [ \"v96\", \"h96\" ] ],\n [ \"led5:A\", \"mega:3\", \"green\", [ \"v57.6\", \"h-19.2\" ] ],\n [ \"mega:GND.2\", \"bb1:8b.j\", \"black\", [ \"v26.7\", \"h267.35\" ] ],\n [ \"led5:C\", \"bb1:8b.g\", \"green\", [ \"v0\" ] ],\n [ \"led4:C\", \"bb1:8b.h\", \"green\", [ \"v0\" ] ],\n [ \"led3:C\", \"bb1:8b.i\", \"green\", [ \"v0\" ] ],\n [ \"bb1:8b.f\", \"bb1:8t.e\", \"green\", [ \"v0\" ] ],\n [ \"led1:C\", \"bb1:8t.c\", \"green\", [ \"v9.6\", \"h-18.8\", \"v-48\" ] ],\n [ \"led2:C\", \"bb1:8t.b\", \"green\", [ \"v19.2\", \"h-18.8\", \"v-76.8\" ] ],\n [ \"led6:C\", \"bb1:8t.a\", \"green\", [ \"v9.6\", \"h-9.2\", \"v-67.2\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for smart buzzer system using esp-32", + "input": "#include \n\nconst int irPin = 14; // GPIO pin connected to the IR receiver\nconst int buzzerPin = 13; // GPIO pin connected to the buzzer\n\nIRrecv irrecv(irPin);\ndecode_results results;\n\nvoid setup() {\n irrecv.enableIRIn(); // Start the receiver\n pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output\n Serial.begin(115200);\n}\n\nvoid loop() {\n if (irrecv.decode(&results)) {\n Serial.println(results.value, HEX); // Print the received IR code in hexadecimal\n \n switch (results.value) {\n case 0xFFA25D: // Example IR code for a specific button\n tone(buzzerPin, 1000, 500); // Play a tone at 1000Hz for 500ms\n break;\n case 0xFF629D: // Another example IR code\n tone(buzzerPin, 2000, 500); // Play a tone at 2000Hz for 500ms\n break;\n // Add more cases for different buttons if needed\n default:\n noTone(buzzerPin); // Turn off the buzzer for unrecognized codes\n break;\n }\n irrecv.resume(); // Receive the next value\n }\n}\n/*IR Receiver Module:\n\nVCC to 3.3V on the ESP32\n\nGND to GND on the ESP32\n\nDAT to 14 on the ESP32\n\nBuzzer:\n\nbz1:2 to 13 on the ESP32\n\nbz1:1 to GND on the ESP32*/", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"wokwi-ir-receiver\", \"id\": \"ir1\", \"top\": -97.35, \"left\": -78.58, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -84,\n \"left\": 97.8,\n \"attrs\": { \"volume\": \"0.1\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"ir1:VCC\", \"esp:3V3\", \"red\", [ \"v0\" ] ],\n [ \"ir1:GND\", \"esp:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"ir1:DATA\", \"esp:14\", \"green\", [ \"v0\" ] ],\n [ \"bz1:1\", \"esp:GND.2\", \"green\", [ \"v0\" ] ],\n [ \"bz:2\", \"esp:13\", \"green\", [ \"v0\" ] ],\n [ \"bz1:2\", \"esp:13\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Smart street light using LDR and arduino-uno", + "input": "const int ldrPin = A0; // Analog pin connected to the LDR\nconst int ledPin = 9; // Digital pin connected to the LED\n\nvoid setup() {\n pinMode(ledPin, OUTPUT);\n Serial.begin(9600);\n}\n\nvoid loop() {\n int ldrValue = analogRead(ldrPin); // Read the value from the LDR\n Serial.println(ldrValue); // Print the LDR value to the Serial Monitor\n\n // Adjust the threshold value according to your needs\n if (ldrValue < 500) {\n digitalWrite(ledPin, HIGH); // Turn on the LED\n } else {\n digitalWrite(ledPin, LOW); // Turn off the LED\n }\n delay(100); // Short delay to avoid rapid changes\n}\n/*Hardware Connections:\nPhotoresistor Sensor (LDR):\nVCC of the LDR to 5V on the Arduino Uno\nAO of the LDR to A0 on the Arduino Uno\nGND of LDR to GND on th Arduino-Uno\nLED:\nA of the LED to a 220\u03a9 resistor, then to D9 on the Arduino Uno\nC of the LED to GND on the Arduino Uno*/", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n {\n \"type\": \"wokwi-photoresistor-sensor\",\n \"id\": \"ldr1\",\n \"top\": -92.8,\n \"left\": 48.8,\n \"attrs\": {}\n },\n { \"type\": \"wokwi-led\", \"id\": \"led1\", \"top\": -51.6, \"left\": 23, \"attrs\": { \"color\": \"green\" } },\n {\n \"type\": \"wokwi-resistor\",\n \"id\": \"r1\",\n \"top\": 72,\n \"left\": 47.45,\n \"rotate\": 90,\n \"attrs\": { \"value\": \"220\" }\n }\n ],\n \"connections\": [\n [ \"ldr1:VCC\", \"uno:5V\", \"red\", [ \"h67.2\", \"v288\", \"h-124.8\" ] ],\n [ \"ldr1:AO\", \"uno:A0\", \"green\", [ \"h57.6\", \"v248.9\", \"h-67.2\" ] ],\n [ \"ldr1:GND\", \"uno:GND.2\", \"black\", [ \"h0\" ] ],\n [ \"led1:A\", \"r1:1\", \"green\", [ \"v0\" ] ],\n [ \"r1:2\", \"uno:9\", \"green\", [ \"h0\" ] ],\n [ \"led1:C\", \"uno:GND.3\", \"black\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Touchless door bell using IR flame sensor,arduino-uno,buzzer", + "input": "// Pin Definitions\nconst int irSensorPin = 2; // Digital pin connected to the IR sensor output\nconst int buzzerPin = 3; // Digital pin connected to the buzzer\n\nvoid setup() {\n // Initialize the IR sensor pin as an input\n pinMode(irSensorPin, INPUT);\n // Initialize the buzzer pin as an output\n pinMode(buzzerPin, OUTPUT);\n // Start the serial communication for debugging purposes\n Serial.begin(9600);\n}\n\nvoid loop() {\n // Read the state of the IR sensor\n int sensorValue = digitalRead(irSensorPin);\n\n // If the sensor detects an object (output is HIGH)\n if (sensorValue == HIGH) {\n // Turn on the buzzer\n digitalWrite(buzzerPin, HIGH);\n Serial.println(\"Visitor detected! Buzzer ON.\");\n } else {\n // Turn off the buzzer\n digitalWrite(buzzerPin, LOW);\n Serial.println(\"No visitor. Buzzer OFF.\");\n }\n\n // Short delay to avoid rapid changes\n delay(100);\n}\n/*IR Sensor Module:\nVCC to 5V on the Arduino Uno\nGND to GND on the Arduino Uno\nDOUT to D2 on the Arduino Uno\nBuzzer:\nbz1:2 to D3 on the Arduino Uno\nbz1:1 to GND on the Arduino Uno*/", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-uno\", \"id\": \"uno\", \"top\": 29.4, \"left\": -0.6, \"attrs\": {} },\n {\n \"type\": \"wokwi-flame-sensor\",\n \"id\": \"led1\",\n \"top\": -81.8,\n \"left\": -16.6,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -84,\n \"left\": 241.8,\n \"attrs\": { \"volume\": \"0.1\" }\n }\n ],\n \"connections\": [\n [ \"led1:VCC\", \"uno:5V\", \"red\", [ \"h28.8\", \"v259.2\", \"h-48\" ] ],\n [ \"led1:GND\", \"uno:GND.1\", \"black\", [ \"h9.6\", \"v76.7\", \"h-76.8\" ] ],\n [ \"bz1:1\", \"uno:GND.2\", \"black\", [ \"v0\" ] ],\n [ \"bz1:2\", \"uno:3\", \"red\", [ \"v0\" ] ],\n [ \"led1:DOUT\", \"uno:2\", \"violet\", [ \"h0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Gas Leakage Detector \u2013 Gas Sensor + Buzzer + ESP32 Devkit V1", + "input": "// Define the pin connections\nconst int gasSensorPin = A0; // Analog pin connected to the gas sensor's AO\nconst int buzzerPin = 13; // Digital pin connected to the buzzer\n\nvoid setup() {\n // Initialize the gas sensor pin as an input\n pinMode(gasSensorPin, INPUT);\n // Initialize the buzzer pin as an output\n pinMode(buzzerPin, OUTPUT);\n // Start the serial communication for debugging purposes\n Serial.begin(115200);\n}\n\nvoid loop() {\n // Read the analog value from the gas sensor\n int sensorValue = analogRead(gasSensorPin);\n \n // Print the sensor value to the Serial Monitor for debugging\n Serial.println(sensorValue);\n \n // Adjust the threshold value according to your needs\n // If the sensor value exceeds the threshold (indicating gas leakage)\n if (sensorValue > 300) {\n // Turn on the buzzer\n digitalWrite(buzzerPin, HIGH);\n Serial.println(\"Gas detected! Buzzer ON.\");\n } else {\n // Turn off the buzzer\n digitalWrite(buzzerPin, LOW);\n Serial.println(\"No gas detected. Buzzer OFF.\");\n }\n\n // Short delay to avoid rapid changes\n delay(100);\n}\n/*Gas Sensor (MQ-2):\nVCC to 3.3V on the ESP32\nGND to GND on the ESP32\nAO to A0 on the ESP32 (Analog output)\nBuzzer:\nbz1:2 to D13 on the ESP32\nbz1:1 to GND on the ESP32*/", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 38.4, \"left\": 14.44, \"attrs\": {} },\n {\n \"type\": \"wokwi-gas-sensor\",\n \"id\": \" \",\n \"top\": -74.1,\n \"left\": -31.4,\n \"attrs\": { \"color\": \"red\" }\n },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": -55.2,\n \"left\": 165,\n \"attrs\": { \"volume\": \"0.1\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \" :VCC\", \"esp:5V\", \"red\", [ \"h19.2\", \"v56.7\", \"h-134.4\", \"v192\" ] ],\n [ \" :GND\", \"esp:GND.2\", \"black\", [ \"h38.4\", \"v104.8\" ] ],\n [ \" :AOUT\", \"esp:0\", \"green\", [ \"h28.8\", \"v249.6\" ] ],\n [ \"bz1:1\", \"esp:GND.1\", \"green\", [ \"v172.8\", \"h-163.2\", \"v-9.6\" ] ],\n [ \"bz1:2\", \"esp:13\", \"green\", [ \"v182.4\", \"h-202\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Gesture-Controlled LED Strip \u2013 MPU6050 + NeoPixel + Arduino Nano", + "input": "#include \n#include \n#include \n\n// Pin definitions\n#define NEOPIXEL_PIN 6 // Data pin for NeoPixel\n#define NUMPIXELS 16 // Number of LEDs in the NeoPixel strip\n\n// Initialize the NeoPixel object\nAdafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);\n\n// Initialize the MPU6050 object\nMPU6050 mpu;\n\nvoid setup() {\n // Start the serial communication for debugging purposes\n Serial.begin(9600);\n \n // Initialize the NeoPixel strip\n strip.begin();\n strip.show(); // Initialize all pixels to 'off'\n \n // Initialize the MPU6050 sensor\n Wire.begin();\n mpu.initialize();\n \n // Check if the MPU6050 is connected\n if (mpu.testConnection()) {\n Serial.println(\"MPU6050 connected successfully!\");\n } else {\n Serial.println(\"MPU6050 connection failed!\");\n }\n}\n\nvoid loop() {\n // Variables to hold accelerometer data\n int16_t ax, ay, az;\n \n // Read the accelerometer data\n mpu.getAcceleration(&ax, &ay, &az);\n \n // Print the accelerometer data for debugging purposes\n Serial.print(\"aX = \"); Serial.print(ax);\n Serial.print(\" | aY = \"); Serial.print(ay);\n Serial.print(\" | aZ = \"); Serial.println(az);\n \n // Map the accelerometer data to LED index\n int ledIndex = map(ax, -17000, 17000, 0, NUMPIXELS - 1);\n \n // Ensure the mapped value is within the LED strip range\n ledIndex = constrain(ledIndex, 0, NUMPIXELS - 1);\n \n // Clear all LEDs\n strip.clear();\n \n // Set the color of the LED based on the gesture\n strip.setPixelColor(ledIndex, strip.Color(255, 0, 0)); // Red color for demonstration\n \n // Show the updated colors on the LED strip\n strip.show();\n \n // Small delay to avoid rapid changes\n delay(100);\n}\n/*Hardware Connections:\nMPU6050 Module:\nVCC to 5V on the Arduino Nano\nGND to GND on the Arduino Nano\nSDA to A4 on the Arduino Nano\nSCL to A5 on the Arduino Nano\nNeoPixel LED Strip:\nVCC to 5V on the Arduino Nano\nGND to GND on the Arduino Nano\nDIN to D6 on the Arduino Nano*/", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"wokwi-arduino-nano\", \"id\": \"nano\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"wokwi-mpu6050\", \"id\": \"imu1\", \"top\": -101.78, \"left\": 31.12, \"attrs\": {} },\n {\n \"type\": \"wokwi-led-ring\",\n \"id\": \"ring1\",\n \"top\": 29.44,\n \"left\": -85.21,\n \"attrs\": { \"pixels\": \"16\" }\n }\n ],\n \"connections\": [\n [ \"imu1:VCC\", \"nano:5V\", \"red\", [ \"v-19.2\", \"h19.28\" ] ],\n [ \"imu1:GND\", \"nano:GND.1\", \"black\", [ \"v-38.4\", \"h48.08\" ] ],\n [ \"imu1:SCL\", \"nano:A5\", \"yellow\", [ \"v0\" ] ],\n [ \"imu1:SDA\", \"nano:A4\", \"white\", [ \"h-9.52\", \"v158.4\" ] ],\n [ \"ring1:DIN\", \"nano:6\", \"green\", [ \"v9.6\", \"h38.4\" ] ],\n [ \"ring1:VCC\", \"nano:5V\", \"cyan\", [ \"v19.2\", \"h153.6\" ] ],\n [ \"ring1:GND\", \"nano:GND.1\", \"#8f4814\", [ \"v28.8\", \"h211.2\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Obstacle Avoidance Robot \u2013 HCSR04 + Stepper Motor + ESP32 Devkit V1", + "input": "// Include necessary libraries\n#include \n\n// Define pin connections\nconst int trigPin = 12; // GPIO pin connected to the HC-SR04 Trig pin\nconst int echoPin = 14; // GPIO pin connected to the HC-SR04 Echo pin\nconst int stepPin = 26; // GPIO pin connected to the A4988 STEP pin\nconst int dirPin = 25; // GPIO pin connected to the A4988 DIR pin\n\n// Variables for distance calculation\nlong duration;\nint distance;\n\nvoid setup() {\n // Set up the pins\n pinMode(trigPin, OUTPUT);\n pinMode(echoPin, INPUT);\n pinMode(stepPin, OUTPUT);\n pinMode(dirPin, OUTPUT);\n\n // Initialize serial communication for debugging\n Serial.begin(115200);\n\n // Set initial motor direction\n digitalWrite(dirPin, HIGH); // Set motor direction clockwise\n}\n\nvoid loop() {\n // Clear the trigPin\n digitalWrite(trigPin, LOW);\n delayMicroseconds(2);\n\n // Set the trigPin HIGH for 10 microseconds\n digitalWrite(trigPin, HIGH);\n delayMicroseconds(10);\n digitalWrite(trigPin, LOW);\n\n // Read the echoPin and calculate the duration\n duration = pulseIn(echoPin, HIGH);\n\n // Calculate the distance\n distance = duration * 0.034 / 2;\n\n // Print the distance to the Serial Monitor\n Serial.print(\"Distance: \");\n Serial.print(distance);\n Serial.println(\" cm\");\n\n // If an obstacle is detected within 20 cm, move the stepper motor backward\n if (distance < 20) {\n Serial.println(\"Obstacle detected! Moving backward.\");\n digitalWrite(dirPin, LOW); // Set motor direction counterclockwise\n\n // Move the motor a few steps backward\n for (int i = 0; i < 200; i++) {\n digitalWrite(stepPin, HIGH);\n delayMicroseconds(500); // Adjust delay for motor speed\n digitalWrite(stepPin, LOW);\n delayMicroseconds(500); // Adjust delay for motor speed\n }\n } else {\n // If no obstacle, move the stepper motor forward\n Serial.println(\"No obstacle. Moving forward.\");\n digitalWrite(dirPin, HIGH); // Set motor direction clockwise\n\n // Move the motor a few steps forward\n for (int i = 0; i < 200; i++) {\n digitalWrite(stepPin, HIGH);\n delayMicroseconds(500); // Adjust delay for motor speed\n digitalWrite(stepPin, LOW);\n delayMicroseconds(500); // Adjust delay for motor speed\n }\n }\n\n // Small delay to avoid rapid changes\n delay(500);\n}\n/*Hardware Connections:\nHC-SR04 Ultrasonic Sensor:\nVCC to 5V on the ESP32\nGND to GND on the ESP32\nTrig to GPIO 12 on the ESP32\nEcho to GPIO 14 on the ESP32\nA4988 Motor Driver:\nVMOT to 12V (external power supply)\nGND to GND (external power supply)\n2B to Step Motor Coil B-\n2A to Step Motor Coil B+\n1A to Step Motor Coil A+\n1B to Step Motor Coil A-\nVDD to 3.3V on ESP32\nGND to GND on ESP32\nSTEP to GPIO 26 on ESP32\nDIR to GPIO 25 on ESP32*/", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 28.8, \"left\": 14.44, \"attrs\": {} },\n { \"type\": \"wokwi-hc-sr04\", \"id\": \"ultrasonic1\", \"top\": -104.1, \"left\": -52.1, \"attrs\": {} },\n {\n \"type\": \"wokwi-stepper-motor\",\n \"id\": \"stepper1\",\n \"top\": -15.59,\n \"left\": -201.17,\n \"attrs\": { \"size\": \"17\" }\n },\n { \"type\": \"wokwi-a4988\", \"id\": \"drv1\", \"top\": 225.6, \"left\": -129.6, \"attrs\": {} },\n { \"type\": \"wokwi-vcc\", \"id\": \"vcc1\", \"top\": 259.96, \"left\": -19.2, \"attrs\": {} },\n { \"type\": \"wokwi-gnd\", \"id\": \"gnd1\", \"top\": 316.8, \"left\": -19.8, \"attrs\": {} }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"ultrasonic1:VCC\", \"esp:5V\", \"red\", [ \"v28.8\", \"h-48\", \"v211.2\", \"h48\" ] ],\n [ \"ultrasonic1:GND\", \"esp:GND.2\", \"black\", [ \"v28.8\", \"h85.2\", \"v38.4\" ] ],\n [ \"ultrasonic1:TRIG\", \"esp:12\", \"green\", [ \"v48\", \"h-29.2\", \"v134.4\" ] ],\n [ \"ultrasonic1:ECHO\", \"esp:14\", \"green\", [ \"v57.6\", \"h-29.6\", \"v115.2\" ] ],\n [ \"drv1:VMOT\", \"vcc1:VCC\", \"green\", [ \"h38.55\", \"v86.48\" ] ],\n [ \"drv1:GND.2\", \"gnd1:GND\", \"black\", [ \"h28.95\", \"v86.48\" ] ],\n [ \"drv1:2B\", \"stepper1:B-\", \"green\", [ \"h19.35\", \"v-67.12\", \"h-48\" ] ],\n [ \"stepper1:B+\", \"drv1:2A\", \"magenta\", [ \"v0\" ] ],\n [ \"stepper1:A+\", \"drv1:1A\", \"gold\", [ \"v0\" ] ],\n [ \"stepper1:A-\", \"drv1:1B\", \"gray\", [ \"v0\" ] ],\n [ \"drv1:VDD\", \"esp:3V3\", \"blue\", [ \"h28.95\", \"v-230.32\" ] ],\n [ \"drv1:GND.1\", \"esp:GND.1\", \"black\", [ \"v0.08\", \"h57.75\", \"v-96\" ] ],\n [ \"drv1:STEP\", \"esp:26\", \"#8f4814\", [ \"h-19.2\", \"v86.4\", \"h172.8\", \"v-230.4\" ] ],\n [ \"drv1:DIR\", \"esp:25\", \"cyan\", [ \"h-9.6\", \"v67.2\", \"h172.8\", \"v-230.4\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for WiFi Weather Dashboard \u2013 ESP32 Devkit V1 + DHT22 + SSD1306", + "input": "#include \n#include \n#include \n#include \n#include \n\n// OLED display dimensions\n#define SCREEN_WIDTH 128\n#define SCREEN_HEIGHT 64\n\n// Declaration for SSD1306 display connected using I2C (SDA, SCL)\nAdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);\n\n// DHT22 sensor\n#define DHTPIN 4\n#define DHTTYPE DHT22\nDHT dht(DHTPIN, DHTTYPE);\n\n// Wi-Fi credentials\nconst char* ssid = \"your_SSID\";\nconst char* password = \"your_PASSWORD\";\n\nvoid setup() {\n Serial.begin(115200);\n\n // Initialize the DHT sensor\n dht.begin();\n\n // Initialize OLED display\n if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) {\n Serial.println(F(\"SSD1306 allocation failed\"));\n for(;;);\n }\n display.display();\n delay(2000);\n display.clearDisplay();\n\n // Connect to Wi-Fi\n WiFi.begin(ssid, password);\n display.print(\"Connecting to WiFi\");\n display.display();\n while (WiFi.status() != WL_CONNECTED) {\n delay(500);\n Serial.print(\".\");\n }\n display.clearDisplay();\n display.print(\"WiFi connected\");\n display.display();\n delay(1000);\n display.clearDisplay();\n}\n\nvoid loop() {\n // Read humidity and temperature values\n float humidity = dht.readHumidity();\n float temperature = dht.readTemperature();\n\n // Check if any reads failed and exit early\n if (isnan(humidity) || isnan(temperature)) {\n Serial.println(F(\"Failed to read from DHT sensor!\"));\n return;\n }\n\n // Display the data on the OLED screen\n display.clearDisplay();\n display.setTextSize(1);\n display.setTextColor(SSD1306_WHITE);\n display.setCursor(0, 0);\n display.print(\"Temperature: \");\n display.print(temperature);\n display.print(\" *C\");\n display.setCursor(0, 10);\n display.print(\"Humidity: \");\n display.print(humidity);\n display.print(\" %\");\n display.display();\n\n delay(2000); // Update every 2 seconds\n}\n/*DHT22 Sensor:\nVCC to 3.3V on the ESP32\nGND to GND on the ESP32\nSDA to GPIO 4 on the ESP32 (with a 10k\u03a9 pull-up resistor to 3.3V)\nSSD1306 OLED Display:\nVCC to 3.3V on the ESP32\nGND to GND on the ESP32\nSDA to GPIO 21 on the ESP32\nSCL to GPIO 22 on the ESP32", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n { \"type\": \"wokwi-dht22\", \"id\": \"dht1\", \"top\": -114.9, \"left\": -82.2, \"attrs\": {} },\n {\n \"type\": \"board-ssd1306\",\n \"id\": \"oled1\",\n \"top\": -64.06,\n \"left\": 134.63,\n \"attrs\": { \"i2cAddress\": \"0x3c\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"dht1:VCC\", \"esp:3V3\", \"red\", [ \"v0\" ] ],\n [ \"dht1:SDA\", \"esp:4\", \"green\", [ \"v0\" ] ],\n [ \"dht1:GND\", \"esp:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"oled1:VCC\", \"esp:3V3\", \"#8f4814\", [ \"v-19.2\", \"h-182.25\" ] ],\n [ \"oled1:GND\", \"esp:GND.2\", \"black\", [ \"v-9.6\", \"h-57.6\", \"v105.6\" ] ],\n [ \"oled1:SCL\", \"esp:22\", \"white\", [ \"v-48\", \"h57.9\", \"v172.8\" ] ],\n [ \"oled1:SDA\", \"esp:21\", \"blue\", [ \"v-28.8\", \"h57.67\", \"v172.8\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for IoT Home Security System\u2013 PIR Motion Sensor + Buzzer + ESP32", + "input": "// Define the pin connections\nconst int pirPin = 13; // GPIO pin connected to the PIR sensor output\nconst int buzzerPin = 12; // GPIO pin connected to the buzzer\n\nvoid setup() {\n // Set up the PIR sensor pin as an input\n pinMode(pirPin, INPUT);\n // Set up the buzzer pin as an output\n pinMode(buzzerPin, OUTPUT);\n // Start the serial communication for debugging purposes\n Serial.begin(115200);\n // Connect to WiFi network\n WiFi.begin(\"your_SSID\", \"your_PASSWORD\");\n while (WiFi.status() != WL_CONNECTED) {\n delay(500);\n Serial.print(\".\");\n }\n Serial.println(\"WiFi connected\");\n}\n\nvoid loop() {\n // Read the state of the PIR sensor\n int sensorValue = digitalRead(pirPin);\n\n // If the sensor detects motion (output is HIGH)\n if (sensorValue == HIGH) {\n // Turn on the buzzer\n digitalWrite(buzzerPin, HIGH);\n Serial.println(\"Motion detected! Buzzer ON.\");\n // Send alert to a server (example URL)\n WiFiClient client;\n if (client.connect(\"example.com\", 80)) {\n client.print(\"GET /alert?motion=detected HTTP/1.1\\r\\n\");\n client.print(\"Host: example.com\\r\\n\");\n client.print(\"Connection: close\\r\\n\\r\\n\");\n client.stop();\n }\n } else {\n // Turn off the buzzer\n digitalWrite(buzzerPin, LOW);\n Serial.println(\"No motion detected. Buzzer OFF.\");\n }\n\n // Small delay to avoid rapid changes\n delay(1000);\n}\n/*Hardware Connections:\nPIR Motion Sensor:\nVCC to 5V on the ESP32\nGND to GND on the ESP32\nOUT to GPIO 13 on the ESP32\nBuzzer:\nbz1:2 to GPIO 12 on the ESP32\nbz1:1 to GND on the ESP32*/", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 249.6, \"left\": 216.04, \"attrs\": {} },\n { \"type\": \"wokwi-pir-motion-sensor\", \"id\": \"pir1\", \"top\": 138.4, \"left\": 50.22, \"attrs\": {} },\n {\n \"type\": \"wokwi-buzzer\",\n \"id\": \"bz1\",\n \"top\": 175.2,\n \"left\": 357,\n \"attrs\": { \"volume\": \"0.1\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"pir1:VCC\", \"esp:5V\", \"red\", [ \"v220.8\", \"h134.4\" ] ],\n [ \"pir1:OUT\", \"esp:13\", \"green\", [ \"v0\" ] ],\n [ \"pir1:GND\", \"esp:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"bz1:1\", \"esp:GND.3\", \"black\", [ \"v0\" ] ],\n [ \"bz1:2\", \"esp:12\", \"green\", [ \"v0\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for IoT-Based Step Counter \u2013 MPU6050 + OLED SSD1306 + ESP32 Devkit V1", + "input": "#include \n#include \n#include \n#include \n\n// OLED display dimensions\n#define SCREEN_WIDTH 128\n#define SCREEN_HEIGHT 64\n\n// Declaration for SSD1306 display connected using I2C (SDA, SCL)\nAdafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);\n\n// MPU6050 sensor\nMPU6050 mpu;\nint stepCounter = 0;\nbool isStep = false;\n\nvoid setup() {\n // Start the serial communication\n Serial.begin(115200);\n \n // Initialize the MPU6050 sensor\n Wire.begin();\n mpu.initialize();\n \n // Check if the MPU6050 is connected\n if (mpu.testConnection()) {\n Serial.println(\"MPU6050 connected successfully!\");\n } else {\n Serial.println(\"MPU6050 connection failed!\");\n }\n\n // Initialize the OLED display\n if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) {\n Serial.println(F(\"SSD1306 allocation failed\"));\n for(;;);\n }\n display.display();\n delay(2000);\n display.clearDisplay();\n\n display.setTextSize(1);\n display.setTextColor(SSD1306_WHITE);\n}\n\nvoid loop() {\n // Variables to hold accelerometer data\n int16_t ax, ay, az;\n\n // Read the accelerometer data\n mpu.getAcceleration(&ax, &ay, &az);\n\n // Simple step detection logic (you may need to adjust thresholds)\n if (abs(ax) > 15000 && !isStep) {\n stepCounter++;\n isStep = true;\n } else if (abs(ax) < 15000) {\n isStep = false;\n }\n // Display step count on the OLED\n display.clearDisplay();\n display.setCursor(0, 0);\n display.print(\"Step Count: \");\n display.print(stepCounter);\n display.display();\n // Small delay to avoid rapid changes\n delay(100);\n}\n/*Hardware Connections:\nMPU6050:\nVCC to 3.3V on the ESP32\nGND to GND on the ESP32\nSDA to GPIO 21 on the ESP32\nSCL to GPIO 22 on the ESP32\nOLED SSD1306 Display:\nVCC to 3.3V on the ESP32\nGND to GND on the ESP32\nSDA to GPIO 21 on the ESP32\nSCL to GPIO 22 on the ESP32*/", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 0, \"left\": 4.84, \"attrs\": {} },\n { \"type\": \"wokwi-mpu6050\", \"id\": \"imu1\", \"top\": -34.58, \"left\": -84.08, \"attrs\": {} },\n {\n \"type\": \"board-ssd1306\",\n \"id\": \"oled1\",\n \"top\": -6.46,\n \"left\": 125.03,\n \"attrs\": { \"i2cAddress\": \"0x3c\" }\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"imu1:VCC\", \"esp:3V3\", \"red\", [ \"v-19.2\", \"h9.68\" ] ],\n [ \"imu1:GND\", \"esp:GND.1\", \"black\", [ \"v0\" ] ],\n [ \"imu1:SCL\", \"esp:22\", \"green\", [ \"v0\" ] ],\n [ \"imu1:SDA\", \"esp:21\", \"green\", [ \"v0\" ] ],\n [ \"oled1:GND\", \"esp:GND.2\", \"black\", [ \"v-38.4\", \"h-57.6\" ] ],\n [ \"oled1:VCC\", \"esp:3V3\", \"red\", [ \"v-9.6\", \"h-163.05\" ] ],\n [ \"oled1:SCL\", \"esp:22\", \"white\", [ \"v-19.2\", \"h-66.9\", \"v96\" ] ],\n [ \"oled1:SDA\", \"esp:21\", \"purple\", [ \"v-28.8\", \"h-67.13\", \"v67.2\" ] ]\n ],\n \"dependencies\": {}\n}" + }, + { + "instruction": "Generate a diagram.json code for Soil moisture measurement using esp32", + "input": "// Define pin connections\nconst int soilMoisturePin = 36; // GPIO pin connected to the Soil Moisture Sensor's AO\n\nvoid setup() {\n // Start serial communication for debugging purposes\n Serial.begin(115200);\n // Initialize the soil moisture sensor pin as an input\n pinMode(soilMoisturePin, INPUT);\n}\n\nvoid loop() {\n // Read the value from the soil moisture sensor\n int sensorValue = analogRead(soilMoisturePin);\n \n // Print the sensor value to the Serial Monitor\n Serial.print(\"Soil Moisture Value: \");\n Serial.println(sensorValue);\n \n // Small delay to avoid rapid changes\n delay(1000);\n}\n/*Hardware Connections:\nSoil Moisture Sensor:\nVCC to 3V3 on the ESP32\nGND to GND on the ESP32\nAO (Analog Output) to A0 (GPIO 36) on the ESP32*/", + "output": "{\n \"version\": 1,\n \"author\": \"Vigneshwaran\",\n \"editor\": \"wokwi\",\n \"parts\": [\n { \"type\": \"board-esp32-devkit-c-v4\", \"id\": \"esp\", \"top\": 0, \"left\": 0, \"attrs\": {} },\n {\n \"type\": \"chip-soil-moisture-sensor\",\n \"id\": \"chip1\",\n \"top\": -66.18,\n \"left\": -62.4,\n \"attrs\": {}\n }\n ],\n \"connections\": [\n [ \"esp:TX\", \"$serialMonitor:RX\", \"\", [] ],\n [ \"esp:RX\", \"$serialMonitor:TX\", \"\", [] ],\n [ \"chip1:VCC\", \"esp:5V\", \"red\", [ \"h-9.6\", \"v249.6\" ] ],\n [ \"chip1:GND\", \"esp:GND.1\", \"black\", [ \"h0\", \"v201.6\" ] ],\n [ \"chip1:AO\", \"esp:0\", \"green\", [ \"v28.8\", \"h69.01\", \"v172.8\" ] ]\n ],\n \"dependencies\": {}\n}\n{\n \"name\": \"soil-moisture-sensor\",\n \"author\": \"Vigneshwaran\",\n \"pins\": [\n \"VCC\",\n \"GND\",\n \"AO\"\n ],\n \"controls\": []\n}" + } +] \ No newline at end of file