#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
// End of constructor list
// this is one way how to define images for u8g library
const uint8_t upir_logo[] U8X8_PROGMEM = {
B10000100, B11011110, // ░░░█░█░███░█░███
B11001101, B00001001, // ░░░█░█░█░█░░░█░█
B10100101, B00001000, // ░░░█░█░██░░█░██░
B10000100, B11001000 // ░░░██░░█░░░█░█░█
};
//#define PI 3.1416
const uint8_t img_bubble_tip[] U8X8_PROGMEM = {
B01111100, //░█████░░
B00111000, //░░███░░░
B00010000 //░░░█░░░░
};
void setup() {
Serial.begin(115200);
u8g2.begin();
u8g2.setColorIndex(1); // white color
//u8g2.setRot180(); // screen rotation by 180°, was better for positioning the display next to knob, but slower in performance
Serial.println("Setup Ok!");
Serial.print("PI:");
Serial.println(PI);
u8g2.clearBuffer();
draw(u8g2);
u8g2.sendBuffer();
}
float seno(int angulo)
{
return sin(angulo * PI / 180);
}
float coseno(int angulo)
{
return cos(angulo * PI / 180);
}
void gauge(uint8_t x, uint8_t y, uint8_t r) {
for(int i=40;i<330; i+=10)
{
int x0=x+(r*seno(i));
int y0=y+(r*coseno(i));
if(i%20)u8g2.drawPixel(x0, y0);
int x1=x+((r+8)*seno(i));
int y1=y+((r+8)*coseno(i));
u8g2.drawPixel(x1, y1);
}
}
void gaugeV(uint8_t x, uint8_t y, uint8_t r, int v) {
int x2=0,y2=0,x3=0,y3=0;
bool p=false;
for(int i=40;i<330; i+=2)
{
int x0=x+(r*seno(i));
int y0=y+(r*coseno(i));
//if(i%20)u8g2.drawPixel(x0, y0);
int x1=x+((r+8)*seno(i));
int y1=y+((r+8)*coseno(i));
if(p && ((v>0 && i<v) ||(v<0 && i>-v)))
{
u8g2.drawTriangle(x0,y0,x1,y1,x2,y2);
u8g2.drawTriangle(x2,y2,x3,y3,x1,y1);
}
p=true;
x2=x0;y2=y0;x3=x1;y3=y1;
}
u8g2.setFont(u8g2_font_unifont_t_symbols);
char cstr[16];
itoa(-v, cstr, 10);
u8g2.drawUTF8(x-(u8g2.getStrWidth(cstr)/2), y+5, cstr);
}
void draw(U8G2 u8g2) {
u8g2.setDrawColor(1);
gauge(28,35,18);
u8g2.sendBuffer();
gauge(99,35,18);
u8g2.sendBuffer();
delay(4000);
gaugeV(28,35,18,-90);
u8g2.sendBuffer();
delay(4000);
gaugeV(99,35,18,-120);
u8g2.sendBuffer();
//u8g2.drawCircle(30, 34, 28, U8G2_DRAW_ALL);
//u8g2.drawCircle(30, 34, 18, U8G2_DRAW_ALL);
//u8g2.drawCircle(98, 34, 28, U8G2_DRAW_ALL);
//u8g2.drawCircle(98, 34, 18, U8G2_DRAW_ALL);
}
void loop(void) {
// picture loop
}