STEAM project — Arduino Uno simulation

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

Components

Sketch code

#include <Wire.h>

// ==================================================
// LCD
// ==================================================

#define LCD_ADDR 0x27

#define LCD_BACKLIGHT 0x08
#define LCD_ENABLE    0x04
#define LCD_RS        0x01


// ==================================================
// RTC DS3231
// ==================================================

#define RTC_ADDR 0x68


// ==================================================
// BOTONES
// ==================================================

#define BOTON_SET    A0
#define BOTON_MAS    A1
#define BOTON_MENOS  A2
#define BOTON_STOP   A3


// ==================================================
// BUZZER
// ==================================================

#define BUZZER 8


// ==================================================
// RELOJ
// ==================================================

byte horas;
byte minutos;
byte segundos;


// ==================================================
// ALARMA
// ==================================================

int alarmaHora = 9;
int alarmaMinuto = 30;

byte modoAlarma = 0;

bool alarmaSonando = false;

unsigned long inicioAlarma = 0;


// ==================================================
// CONTROL LCD
// ==================================================

int ultimoSegundo = -1;


// ==================================================
// ESTADOS DE BOTONES
// ==================================================

bool estadoSET = HIGH;
bool estadoMAS = HIGH;
bool estadoMENOS = HIGH;


// ==================================================
// LCD
// ==================================================

void lcdWrite4Bits(byte data) {

  Wire.beginTransmission(LCD_ADDR);
  Wire.write(data | LCD_BACKLIGHT);
  Wire.endTransmission();

  Wire.beginTransmission(LCD_ADDR);
  Wire.write(data | LCD_BACKLIGHT | LCD_ENABLE);
  Wire.endTransmission();

  delayMicroseconds(1);

  Wire.beginTransmission(LCD_ADDR);
  Wire.write((data | LCD_BACKLIGHT) & ~LCD_ENABLE);
  Wire.endTransmission();

  delayMicroseconds(50);
}


void lcdSend(byte value, byte mode) {

  byte alto = value & 0xF0;
  byte bajo = (value << 4) & 0xF0;

  lcdWrite4Bits(alto | mode);
  lcdWrite4Bits(bajo | mode);
}


void lcdCommand(byte comando) {

  lcdSend(comando, 0);
}


void lcdData(byte dato) {

  lcdSend(dato, LCD_RS);
}


void lcdClear() {

  lcdCommand(0x01);

  delay(2);
}


void lcdSetCursor(byte columna, byte fila) {

  byte posiciones[] = {
    0x00,
    0x40
  };

  lcdCommand(
    0x80 +
    posiciones[fila] +
    columna
  );
}


void lcdPrint(const char *texto) {

  while (*texto) {

    lcdData(*texto);

    texto++;
  }
}


void lcdInit() {

  delay(50);

  lcdWrite4Bits(0x30);

  delay(5);

  lcdWrite4Bits(0x30);

  delayMicroseconds(150);

  lcdWrite4Bits(0x30);

  lcdWrite4Bits(0x20);

  lcdCommand(0x28);

  lcdCommand(0x0C);

  lcdCommand(0x06);

  lcdClear();
}


// ==================================================
// RTC
// =================================================