oscbro — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by bharatgonapa06.

Components

Sketch code

#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define PIN_ADC 35
#define PIN_SDA 21
#define PIN_SCL 22

Adafruit_SSD1306 display(128, 64, &Wire, -1);
uint16_t buf[128];

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
  analogSetAttenuation(ADC_11db); // 0-3.3V
  
  Wire.begin(PIN_SDA, PIN_SCL);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    while(1);
  }
}

void loop() {
  // 1. Capture Data
  for (int i = 0; i < 128; i++) {
    buf[i] = analogRead(PIN_ADC);
    delayMicroseconds(50); 
  }

  // 2. Draw
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  
  // Draw the wave (zoomed in)
  for (int x = 1; x < 128; x++) {
    // We map only the middle range of the ADC (0 to 2000) to the screen
    // This makes a 0-1.5V signal look huge on the screen
    int y0 = map(buf[x-1], 0, 2000, 63, 0);
    int y1 = map(buf[x], 0, 2000, 63, 0);
    
    // Constrain so it doesn't draw outside the box
    y0 = constrain(y0, 0, 63);
    y1 = constrain(y1, 0, 63);
    
    display.drawLine(x-1, y0, x, y1, SSD1306_WHITE);
  }
  
  display.display();
}

More projects by bharatgonapa06