Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Arduino OLED Voltmeter
- #include <Wire.h>
- #include "U8glib.h"
- U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);
- int analogInput = 0;
- float vout = 0.0;
- float vin = 0.0;
- float R1 = 100000.0;
- float R2 = 10000.0;
- int value = 0;
- void draw(void)
- {
- u8g.setFont(u8g_font_profont17r);
- u8g.drawStr(18, 12, "VOLTAGE");
- u8g.setPrintPos(33,40);
- u8g.drawRFrame(15, 20, 100, 30, 10);
- u8g.println(vin);
- u8g.println("V");
- }
- void setup(){
- pinMode(analogInput, INPUT);
- }
- void loop(){
- value = analogRead(analogInput);
- vout = (value * 5.0) / 1024.0;
- vin = vout / (R2/(R1+R2));
- if (vin<0.09) {
- vin=0.0;
- }
- u8g.firstPage();
- do
- {
- draw();
- }
- while( u8g.nextPage() );
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement