Monday, April 16, 2018

LCD I2C to Display A0 Voltage (0V - 5V)

[pastacode lang="c" manual="%23include%20%3CWire.h%3E%20%2F%2F%20Arduino%20IDE%20%E5%85%A7%E5%BB%BA%0A%2F%2F%20LCD%20I2C%20Library%EF%BC%8C%E5%BE%9E%E9%80%99%E8%A3%A1%E5%8F%AF%E4%BB%A5%E4%B8%8B%E8%BC%89%EF%BC%9A%0A%2F%2F%20bitbucket.org%2Ffmalpartida%2Fnew-liquidcrystal%2Fdownloads%0A%23include%20%3CLiquidCrystal_I2C.h%3E%0A%0A%2F%2F%20Set%20the%20pins%20on%20the%20I2C%20chip%20used%20for%20LCD%20connections%3A%0A%2F%2F%20addr%2C%20en%2Crw%2Crs%2Cd4%2Cd5%2Cd6%2Cd7%2Cbl%2Cblpol%0ALiquidCrystal_I2C%20lcd(0x27%2C%202%2C%201%2C%200%2C%204%2C%205%2C%206%2C%207%2C%203%2C%20POSITIVE)%3B%20%2F%2F%20%E8%A8%AD%E5%AE%9A%20LCD%20I2C%20%E4%BD%8D%E5%9D%80%0Afloat%20sensorValue0%20%3D%200.0%3B%0Afloat%20sensorValue1%20%3D%200.0%3B%0AString%20title%20%3D%20%22Output%20Voltage%22%3B%0A%0A%2F%2F%23define%20MIN_VALUE%200%3B%20%20%20%20%2F%2FINPUT%20RANGE%200-1023%0A%23define%20MAX_VALUE%201023.0%0A%0A%2F%2F%23define%20DISPLAY_MIN%200%3B%20%20%2F%2FDISPLAY%20RANGE%200V-5V%0A%23define%20DISPLAY_MAX%205.0%0A%0A%0A%0Avoid%20setup()%20%7B%0ASerial.begin(9600)%3B%20%2F%2F%20%E7%94%A8%E6%96%BC%E6%89%8B%E5%8B%95%E8%BC%B8%E5%85%A5%E6%96%87%E5%AD%97%0Alcd.begin(16%2C%202)%3B%20%2F%2F%20%E5%88%9D%E5%A7%8B%E5%8C%96%20LCD%EF%BC%8C%E4%B8%80%E8%A1%8C%2016%20%E7%9A%84%E5%AD%97%E5%85%83%EF%BC%8C%E5%85%B1%202%20%E8%A1%8C%EF%BC%8C%E9%A0%90%E8%A8%AD%E9%96%8B%E5%95%9F%E8%83%8C%E5%85%89%0A%0A%2F%2F%20%E9%96%83%E7%88%8D%E4%B8%80%E6%AC%A1%0Afor(int%20i%20%3D%200%3B%20i%20%3C%201%3B%20i%2B%2B)%20%7B%0Alcd.backlight()%3B%20%2F%2F%20%E9%96%8B%E5%95%9F%E8%83%8C%E5%85%89%0Adelay(250)%3B%0Alcd.noBacklight()%3B%20%2F%2F%20%E9%97%9C%E9%96%89%E8%83%8C%E5%85%89%0Adelay(250)%3B%0A%7D%0Alcd.backlight()%3B%0A%0A%2F%2F%20%E8%BC%B8%E5%87%BA%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%87%E5%AD%97%0Alcd.setCursor(0%2C%200)%3B%20%2F%2F%20%E8%A8%AD%E5%AE%9A%E6%B8%B8%E6%A8%99%E4%BD%8D%E7%BD%AE%E5%9C%A8%E7%AC%AC%E4%B8%80%E8%A1%8C%E8%A1%8C%E9%A6%96%0Alcd.print(%22HK%20STEM%20CLUB%22)%3B%0Alcd.setCursor(0%2C%201)%3B%20%2F%2F%20%E8%A8%AD%E5%AE%9A%E6%B8%B8%E6%A8%99%E4%BD%8D%E7%BD%AE%E5%9C%A8%E7%AC%AC%E4%BA%8C%E8%A1%8C%E8%A1%8C%E9%A6%96%0Alcd.print(%22hkstem.club%22)%3B%0Adelay(500)%3B%0A%0A%7D%0A%0Avoid%20loop()%20%7B%0A%20%20lcd.clear()%3B%0A%20%20int%20analog_value%20%3D%20analogRead(A0)%3B%0A%20%20sensorValue0%20%3D%20analog_value%20%2F%20MAX_VALUE%3B%20%2F%2F%20read%20the%20input%20on%20analog%20pin%200%3A%0A%20%20%0A%20%20%2F%2F%20print%20out%20the%20sensor%3A%0A%20%20lcd.setCursor(0%2C%200)%3B%0A%20%20lcd.print(sensorValue0%20*%20DISPLAY_MAX)%3B%0A%20%20Serial.println(analog_value%20%2F%201023.0)%3B%0A%0A%20%20lcd.setCursor(0%2C1)%3B%0A%20%20%2F%2Flcd.print(sensorValue1)%3B%0A%20%20lcd.print(title)%3B%0A%0A%20%20sensorValue1%20%3D%20sensorValue0%3B%0A%20%20%0A%20%20delay(300)%3B%20%20%20%20%20%20%20%20%2F%2F%20delay%20in%20between%20reads%20for%20stability%0A%0A%0A%7D" message="" highlight="" provider="manual"/]

No comments: