Boboboi jomok kuasa 9 — Arduino Uno simulation

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

Components

Sketch code

#include <Wire.h>

// =====================================================
// PENGATURAN LCD I2C
// =====================================================

// Alamat I2C LCD yang umum adalah 0x27
// Jika LCD tidak tampil, coba ganti menjadi 0x3F
#define LCD_ADDR 0x27

#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00

// =====================================================
// PIN LED
// =====================================================

const int LED1 = 2;
const int LED2 = 3;
const int LED3 = 4;
const int LED4 = 5;
const int LED5 = 6;
const int LED6 = 7;
const int LED7 = 8;
const int LED8 = 9;
const int LED9 = 10;

// =====================================================
// FUNGSI LCD I2C
// =====================================================

void lcdWrite(uint8_t data)
{
  Wire.beginTransmission(LCD_ADDR);
  Wire.write(data);
  Wire.endTransmission();
}

void lcdPulseEnable(uint8_t data)
{
  lcdWrite(data | 0x04);
  delayMicroseconds(1);

  lcdWrite(data & ~0x04);
  delayMicroseconds(50);
}

void lcdWrite4Bits(uint8_t data)
{
  lcdWrite(data);
  lcdPulseEnable(data);
}

void lcdSend(uint8_t value, uint8_t mode)
{
  uint8_t highNibble = value & 0xF0;
  uint8_t lowNibble  = (value << 4) & 0xF0;

  lcdWrite4Bits(highNibble | mode | LCD_BACKLIGHT);
  lcdWrite4Bits(lowNibble | mode | LCD_BACKLIGHT);
}

void lcdCommand(uint8_t command)
{
  lcdSend(command, 0x00);
}

void lcdData(uint8_t data)
{
  lcdSend(data, 0x01);
}

void lcdClear()
{
  lcdCommand(0x01);
  delay(2);
}

void lcdSetCursor(uint8_t col, uint8_t row)
{
  uint8_t rowOffsets[] = {0x00, 0x40};

  lcdCommand(0x80 | (col + rowOffsets[row]));
}

void lcdPrint(const char *text)
{
  while (*text)
  {
    lcdData(*text);
    text++;
  }
}

void lcdInit()
{
  delay(50);

  // Inisialisasi LCD 4-bit
  lcdWrite4Bits(0x30 | LCD_BACKLIGHT);
  delay(5);

  lcdWrite4Bits(0x30 | LCD_BACKLIGHT);
  delayMicroseconds(150);

  lcdWrite4Bits(0x30 | LCD_BACKLIGHT);
  delayMicroseconds(150);

  lcdWrite4Bits(0x20 | LCD_BACKLIGHT);
  delayMicroseconds(150);

  // Konfigurasi LCD
  lcdCommand(0x28);  // 4-bit, 2 baris, 5x8
  lcdCommand(0x08);  // Display OFF
  lcdClear();
  lcdCommand(0x06);  // Cursor bergerak ke kanan
  lcdCommand(0x0C);  // Display ON, cursor OFF
}

// =====================================================
// FUNGSI MEMATIKAN SEMUA LED
// =====================================================

void matikanSemuaLED()
{
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  digitalWrite(LED6, LOW);
  digitalWrite(LED7, LOW);
  digitalWrite(LED8, LOW);
  digitalWrite(LED9, LOW);
}

// =====================================================
// SETUP
// =====================================================

void setup()
{
  // Inisialisasi pin LED
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LE

More projects by kiybiy36