Skip to content

Instantly share code, notes, and snippets.

@eldonwilliams
Created March 4, 2026 16:52
Show Gist options
  • Select an option

  • Save eldonwilliams/85019f1218596b995dc0a8bcdb7df7b9 to your computer and use it in GitHub Desktop.

Select an option

Save eldonwilliams/85019f1218596b995dc0a8bcdb7df7b9 to your computer and use it in GitHub Desktop.
Arduino lab programming 2 ENGR 111 UofL
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
pinMode(A0, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
float lastUpdTime = 0;
const float updLimit = 1000/3;
int DISP_FPLIM() {
if (millis() - lastUpdTime <= updLimit) {
return 0;
}
lastUpdTime = millis();
return 1;
}
void loop() {
// PRGM 1
float x = float(analogRead(A0));
if (!DISP_FPLIM()) return;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(String(x));
// PRGM 2
lcd.setCursor(0,1);
float v = 5 * x / 1023;
lcd.print(String(v) + " V");
// ADC Mode
digitalWrite(2, v > 2.5 ? HIGH : LOW);
analogWrite(3, v / 5 * 255);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment