displaying on SSD1306, 128x64 pixels OLED
example_OLED.cpp
- Committer:
- bvirk
- Date:
- 2020-02-25
- Revision:
- 12:b4d5e007640e
- Parent:
- 6:c69f08f464b5
File content as of revision 12:b4d5e007640e:
#include "MicroBit.h" #include "MicroBitPin.h" #include "common.h" void example_OLED() { oled.init(); oled.puts("*** VOLTMETER ****\n\n"); char spin[] = "|/-\\"; uint8_t si=0; float oldVoltage=0; while(true) { uint16_t samples =uBit.io.P0.getAnalogValue(); float voltage = 3.3*samples/1023; int8_t dir = voltage - oldVoltage > 0.01 ? 1 : voltage - oldVoltage < -0.01 ? -1 : 0; if (dir) { si = (si+dir) & 3; oldVoltage=voltage; } oled.printf("\r%c %03.2f volt ",spin[si],voltage); } }