// ------------------------------------------
// Show all the resistors of the E12 series.
// ------------------------------------------
// This sketch generates the diagram.json file for this Wokwi project.
// Both \r and \n cause a new line, therefor Serial.println() is not used.
#define NUMBERS 12
const int E12[NUMBERS] = {10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82 };
void setup()
{
Serial.begin( 115200);
// ------------------------------------------
// Header of diagram.json
// ------------------------------------------
Serial.print( "{\n");
Serial.print( " \"version\": 1,\n");
Serial.print( " \"author\": \"Generated by sketch\",\n");
Serial.print( " \"editor\": \"wokwi\",\n");
Serial.print( " \"parts\": [\n");
// ------------------------------------------
// The resistors
// ------------------------------------------
int count = 1; // counter for resistor id
for( int i=-2; i<7; i++) // start at 0.1, stop before 100M
{
for( int j=0; j<NUMBERS; j++)
{
// Build the string for the value.
// Using 32-bit float could not do the full range.
char buffer[20];
if( i < 0)
{
float fValue = E12[j] * pow( 10.0, float(i));
dtostrf( fValue, -5, 2, buffer);
}
else
{
itoa( E12[j], buffer, 10);
for( int z=0; z<i; z++)
{
strcat( buffer, "0");
}
}
Serial.print( " {\n");
Serial.print( " \"type\": \"wokwi-resistor\",\n");
Serial.print( " \"id\": \"r");
Serial.print( count++);
Serial.print( "\",\n");
Serial.print( " \"top\": ");
Serial.print( 20 + (j*20));
Serial.print( ",\n");
Serial.print( " \"left\": ");
Serial.print( 20 + ((i+2) * 75));
Serial.print( ",\n");
Serial.print( " \"rotate\": 0,\n");
Serial.print( " \"hide\": false,\n");
Serial.print( " \"attrs\": { \"value\": \"");
Serial.print( buffer);
Serial.print( "\" }\n");
Serial.print( " },\n");
}
}
// ------------------------------------------
// The Arduino Uno.
// It is required to run this sketch to generate the diagram.json
// ------------------------------------------
Serial.print( " {\n");
Serial.print( " \"type\": \"wokwi-arduino-uno\",\n");
Serial.print( " \"id\": \"uno\",\n");
Serial.print( " \"top\": 280,\n");
Serial.print( " \"left\": 10,\n");
Serial.print( " \"rotate\": 0,\n");
Serial.print( " \"hide\": false,\n");
Serial.print( " \"attrs\": {}\n");
Serial.print( " }\n");
// ------------------------------------------
// Trailer of diagram.json
// ------------------------------------------
Serial.print( " ],\n");
Serial.print( " \"connections\": []\n");
Serial.print( "}\n");
}
void loop()
{
}