Created
March 4, 2026 16:52
-
-
Save eldonwilliams/85019f1218596b995dc0a8bcdb7df7b9 to your computer and use it in GitHub Desktop.
Arduino lab programming 2 ENGR 111 UofL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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