int ontime,offtime,duty;
float freq,period;
uint8_t pwm=0;
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
int progress = 0;
void setup() {
u8g.setFont(u8g_font_tpssb);
u8g.setColorIndex(1);
pinMode(2, INPUT);
}
void loop() {
ontime = pulseIn(10,HIGH);
offtime = pulseIn(10,LOW);
period = ontime+offtime;
freq = 1000000.0/period;
duty = (ontime/period)*100;
freq = 1000000.0/period;
u8g.firstPage();
do {
u8g.drawStr(25, 50, "Power: ");
u8g.setPrintPos(70,50);
u8g.print(freq);
u8g.drawFrame(0, 10, 128, 20);
u8g.drawBox(10, 15, progress, 10);
} while ( u8g.nextPage() );
if (progress < 108) {
progress++;
} else {
progress = 0;
}
}