Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://en.wikipedia.org/wiki/Bresenham's_line_algorithm
- #include <EEPROM.h>
- #include <SPI.h>
- #define testbit(data,bitno) ((data>>bitno)&0x001) //Byte manipulation macros
- #define bit_set(var,bitno) ((var) |= 1 << (bitno))
- #define bit_clr(var,bitno) ((var) &= ~(1 << (bitno)))
- #define SSD1306 0 // Definice displeje SSD1306
- #define SSD1309 1 // displej SSD1309
- #define SH1106 2 // Displej SH1106
- #define disp_type SH1106
- //int disp_type=SH1106; // Tady je konkretni vyber
- //int disp_type=SSD1309; // Tady je konkretni vyber
- //int disp_type=SSD1306; // Tady je konkretni vyber
- // nadefinovani PINu konkr. displeje
- #define RST 4 //PD4
- #define DC 3 //PD3
- #define CS0 2 //PD2 Left Display Chip Select
- #define CS1 7 //PD7 Right Display Chip Select
- #define CK 6 //PD6 SCK 13
- #define DA 5 //PD5 MOSI 11
- #define Plus 6 //increase brightness
- #define Minus 5 //decrease brightness
- #define BTN 8 //Mode select button
- #define A0 14 //Left Audio Input
- #define A1 15 //Right Audio Input
- #define LED 13
- #define CMD 0
- #define DATA 1
- //Display in normal or inverted pixels
- #define NORM 0
- #define INV 1
- #define Disp0 0 //Left Display
- #define Disp1 1 //Right Display
- char PHYS=1; //enable needle mass spring physics response, 0 no physics, 1 underdamped, 2 overdamped
- // p ,i
- // 0.2,0.8 - lots of overshoot/oscillations around setpoint, slower settling, underdamped
- // 0.5,0.1 - quicker settling, little overshoot/oscillations, overdamped
- double p_gain=0.2;
- double i_gain=0.8;
- unsigned char brt=207; //Display Brightness
- unsigned char dispbuff[1026]={128,64}; //Display Buffer to be sent to OLED
- const char Rbackground[] PROGMEM = {128,64, //Right VU Meter Background
- 0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x80,
- 0x00,0xCE,0x0A,0x0B,0x80,0x0F,0x08,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x0F,0x08,0x80,0x0F,0x08,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x8A,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x8A,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x8A,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x8F,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE8,0x0F,0x00,0x00,0x00,0x09,0xCF,0x08,0x00,0x00,0x00,0x0E,0xCA,0x0B,0x00,0x00,0x00,0x08,0xCA,0x0F,
- 0x80,0xBB,0x8A,0x0A,0x0B,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x8A,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x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x04,0x04,0x04,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x1F,0x04,0x04,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x02,0xF2,0x92,0x92,0x62,0x04,0x08,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,0x3C,0x04,0x08,0x30,0x42,0x45,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- };
- const char Lbackground[] PROGMEM = {128,64, //Left VU Meter Background
- //const int Lbackground[] PROGMEM = {128,64, // Pomohlo od Warnings
- 0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x80,
- 0x00,0xCE,0x0A,0x0B,0x80,0x0F,0x08,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x0F,0x08,0x80,0x0F,0x08,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x8A,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x8A,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x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0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0A,0x0E,0x00,0x0F,0x08,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0A,0x0F,0x00,0x0F,0x08,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x0F,0x08,0x00,0x0F,0x08,0x0F,0x00,0x0F,0x08,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x04,0x04,0x04,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x1F,0x04,0x04,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x02,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,0x4F,0x48,0x48,0x48,0x48,0x48,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- };
- const char SmallFont[] PROGMEM = {0x05,0x08, //5x7 Small 8 bit Font
- 0x00,0x00,0x00,0x00,0x00, // ' ' , 480 bytes
- 0x00,0x00,0x5F,0x00,0x00, // !
- 0x00,0x07,0x00,0x07,0x00, // "
- 0x14,0x7F,0x14,0x7F,0x14, // #
- 0x24,0x2A,0x7F,0x2A,0x12, // $
- 0x23,0x13,0x08,0x64,0x62, // %
- 0x36,0x49,0x55,0x22,0x50, // &
- 0x00,0x05,0x03,0x00,0x00, // '
- 0x00,0x1C,0x22,0x41,0x00, // (
- 0x00,0x41,0x22,0x1C,0x00, // )
- 0x14,0x08,0x3E,0x08,0x14, // *
- 0x08,0x08,0x3E,0x08,0x08, // +
- 0x00,0x50,0x30,0x00,0x00, // ,
- 0x08,0x08,0x08,0x08,0x08, // -
- 0x00,0x60,0x60,0x00,0x00, // .
- 0x40,0x20,0x10,0x08,0x04, // /
- 0x3E,0x51,0x49,0x45,0x3E, //0
- 0x00,0x42,0x7F,0x40,0x00, //1
- 0x42,0x61,0x51,0x49,0x46, //2
- 0x22,0x49,0x49,0x49,0x36, //3
- 0x18,0x14,0x12,0x7F,0x10, //4
- 0x27,0x45,0x45,0x45,0x39, //5
- 0x3E,0x49,0x49,0x49,0x32, //6
- 0x01,0x01,0x71,0x09,0x07, //7
- 0x36,0x49,0x49,0x49,0x36, //8
- 0x26,0x49,0x49,0x49,0x3E, //9
- 0x00,0x36,0x36,0x00,0x00, // :
- 0x00,0x56,0x36,0x00,0x00, // ;
- 0x08,0x14,0x22,0x41,0x00, // <
- 0x14,0x14,0x14,0x14,0x14, // =
- 0x41,0x22,0x14,0x08,0x00, // >
- 0x02,0x01,0x51,0x09,0x06, // ?
- 0x32,0x49,0x79,0x41,0x3E, // @
- 0x7C,0x12,0x11,0x12,0x7C, //A
- 0x7F,0x49,0x49,0x49,0x36, //B
- 0x3E,0x41,0x41,0x41,0x22, //C
- 0x7F,0x41,0x41,0x41,0x3E, //D
- 0x7F,0x49,0x49,0x49,0x41, //E
- 0x7F,0x09,0x09,0x09,0x01, //F
- 0x3E,0x41,0x49,0x49,0x7A, //G
- 0x7F,0x08,0x08,0x08,0x7F, //H
- 0x00,0x41,0x7F,0x41,0x00, //I
- 0x20,0x41,0x41,0x3F,0x01, //J
- 0x7F,0x08,0x14,0x22,0x41, //K
- 0x7F,0x40,0x40,0x40,0x40, //L
- 0x7F,0x02,0x0C,0x02,0x7F, //M
- 0x7F,0x04,0x08,0x10,0x7F, //N
- 0x3E,0x41,0x41,0x41,0x3E, //O
- 0x7F,0x09,0x09,0x09,0x06, //P
- 0x3E,0x41,0x51,0x21,0x5E, //Q
- 0x7F,0x09,0x19,0x29,0x46, //R
- 0x26,0x49,0x49,0x49,0x32, //S
- 0x01,0x01,0x7F,0x01,0x01, //T
- 0x3F,0x40,0x40,0x40,0x3F, //U
- 0x1F,0x20,0x40,0x20,0x1F, //V
- 0x3F,0x40,0x38,0x40,0x3F, //W
- 0x63,0x14,0x08,0x14,0x63, //X
- 0x07,0x08,0x70,0x08,0x07, //Y
- 0x61,0x51,0x49,0x45,0x43, //Z
- 0x00,0x7F,0x41,0x41,0x00, // [
- 0x15,0x16,0x7C,0x16,0x15, // Yen
- 0x00,0x41,0x41,0x7F,0x00, // ]
- 0x04,0x02,0x01,0x02,0x04, // ^
- 0x40,0x40,0x40,0x40,0x40, // _
- 0x00,0x01,0x02,0x04,0x00, // `
- 0x20,0x54,0x54,0x54,0x78, //a
- 0x7F,0x48,0x44,0x44,0x38, //b
- 0x38,0x44,0x44,0x44,0x20, //c
- 0x38,0x44,0x44,0x48,0x7F, //d
- 0x38,0x54,0x54,0x54,0x18, //e
- 0x08,0x7E,0x09,0x01,0x02, //f
- 0x0C,0x52,0x52,0x52,0x3E, //g
- 0x7F,0x08,0x04,0x04,0x78, //h
- 0x00,0x44,0x7D,0x40,0x00, //i
- 0x20,0x40,0x44,0x3D,0x00, //j
- 0x7F,0x10,0x28,0x44,0x00, //k
- 0x00,0x41,0x7F,0x40,0x00, //l
- 0x7C,0x04,0x18,0x04,0x78, //m
- 0x7C,0x08,0x04,0x04,0x78, //n
- 0x38,0x44,0x44,0x44,0x38, //o
- 0x7C,0x14,0x14,0x14,0x08, //p
- 0x08,0x14,0x14,0x18,0x7C, //q
- 0x7C,0x08,0x04,0x04,0x08, //r
- 0x48,0x54,0x54,0x54,0x24, //s
- 0x04,0x3F,0x44,0x40,0x20, //t
- 0x3C,0x40,0x40,0x20,0x7C, //u
- 0x1C,0x20,0x40,0x20,0x1C, //v
- 0x3C,0x40,0x38,0x40,0x3C, //w
- 0x44,0x28,0x10,0x28,0x44, //x
- 0x0C,0x50,0x50,0x50,0x3C, //y
- 0x44,0x64,0x54,0x4C,0x44, //z
- 0x00,0x08,0x36,0x41,0x00, // {
- 0x00,0x00,0x7F,0x00,0x00, // |
- 0x00,0x41,0x36,0x08,0x00, // }
- 0x08,0x08,0x2A,0x1C,0x08, // ->
- 0x08,0x1C,0x2A,0x08,0x08};// <-
- // Reset displeje
- void dispRST(void){
- delay(10);
- digitalWrite(RST,LOW);
- delay(10);
- digitalWrite(RST,HIGH);
- delay(10);
- }
- // Přenos bytu přes sběrnici SPI do displeje
- void spi_byte(char b){ //only for bitbanged SPI implementation
- for (int i = 0; i < 8; i++) {
- //PORTD&=~(1<<CK); //digitalWrite(CK, LOW);
- //if((b >> (7 - i) & 0b1)){PORTD|=1<<DA;}else{PORTD&=~(1<<DA);} //digitalWrite(DA, (b >> (7 - i) & 0b1));
- //PORTD|=1<<CK; //digitalWrite(CK, HIGH);
- }
- }
- void spi_start(bool ch){
- if(!ch){
- PORTD&=~(1<<CS0); //digitalWrite(CS, LOW);
- }else{
- PORTD&=~(1<<CS1);
- }
- }
- void spi_end(){
- PORTD|=1<<CS0; //digitalWrite(CS, HIGH);
- PORTD|=1<<CS1;
- //PORTD&=~(1<<CK); //digitalWrite(CK, LOW);
- //PORTD&=~(1<<DA); //digitalWrite(DA, LOW);
- PORTD&=~(1<<DC); //digitalWrite(DC, LOW);
- }
- void spi_write(bool D_C, char b, bool ch){
- if(D_C){PORTD|=1<<DC;}else{PORTD&=~(1<<DC);} //digitalWrite(DC,D_C);
- spi_start(ch);
- //spi_byte(b);
- SPI.transfer(b);
- spi_end();
- }
- void disp_init(bool ch){
- spi_write(CMD,0xAE,ch); //Set display off
- spi_write(CMD,0xD5,ch); //Set display clock divide ratio
- spi_write(CMD,0x80,ch); //Set display oscillator freq
- spi_write(CMD,0xA8,ch); //Set multiplex ratio
- spi_write(CMD,0x3F,ch);
- spi_write(CMD,0xD3,ch); //Set display offset
- spi_write(CMD,0x00,ch);
- spi_write(CMD,0x40,ch); //Set display start line
- //spi_write(CMD,0x8D,ch); //Set charge pump
- //spi_write(CMD,0x14,ch);
- spi_write(CMD,0xA1,ch); //Set segment remap
- spi_write(CMD,0xC8,ch); //Set com output scan dir
- spi_write(CMD,0xDA,ch); //Set com pins hardware config
- spi_write(CMD,0x12,ch);
- spi_write(CMD,0x81,ch); //Set contrast control
- spi_write(CMD,0xCF,ch);
- spi_write(CMD,0xD9,ch); //Set precharge period
- spi_write(CMD,0xF1,ch);
- spi_write(CMD,0xDB,ch); //Set vcomh deselect level
- spi_write(CMD,0x40,ch);
- spi_write(CMD,0xA4,ch); //Set entire display on/off
- spi_write(CMD,0xA6,ch); //Set normal/inverse display
- spi_write(CMD,0x20,ch); //Set memory addressing mode
- spi_write(CMD,0x00,ch);
- spi_write(CMD,0xAF,ch); //Set display on
- }
- void brightness(unsigned char b){
- for(int i=0;i<2;i++){
- spi_write(CMD,0x81,i); //Set contrast control
- spi_write(CMD,b,i);
- }
- }
- void printchar(char c, int font, bool inv, bool ch){
- unsigned char w,h=0;
- w = pgm_read_byte_near(font);
- h = pgm_read_byte_near(font + 1);
- for(int i=0;i<5;i++){
- spi_write(DATA,pgm_read_byte_near(font+2+(w*h/8)*(c-32)+i),ch);
- }
- spi_write(DATA,0x00,ch);
- }
- void writeString(String str, bool ch){
- unsigned char len = str.length();
- unsigned char p=0;
- while(p<len){
- printchar(str.charAt(p),SmallFont,NORM,ch);
- p++;
- }
- }
- void clr(bool ch){
- if(disp_type==SSD1306||disp_type==SSD1309){
- for(int i=0;i<8192;i++){
- spi_write(DATA,0x00,ch);
- }
- }else{
- for(int j=0;j<8;j++){
- set_xy(0,j,ch);
- for(int i=0;i<128;i++){
- spi_write(DATA,0x00,ch);
- }
- }
- }
- set_xy(0,0,ch);
- }
- void set_xy(char x, char y, bool ch){
- if(disp_type==SSD1306||disp_type==SSD1309){
- spi_write(CMD,0x21,ch); //set x
- spi_write(CMD,0x00+x,ch);
- spi_write(CMD,0x7F,ch);
- spi_write(CMD,0xB0+y,ch); //set y
- }else{
- x+=2;
- spi_write(CMD,0xB0|y,ch); //set y
- //spi_write(CMD,y);
- spi_write(CMD,x&0x0F,ch); //set x
- spi_write(CMD,((x>>4)&0x0F)|0x10,ch);
- }
- }
- void drawBMP(int x, int y, unsigned long bmp, unsigned char elem, bool inv, bool ch){ //write bitmap image to location X,Y on screen, can specify array bmp and elem index of image
- unsigned char w=*(char*)bmp; //must cast to obtain value in ram given the address
- unsigned char h=*(char*)(bmp+1);
- for(int j=0;j<h/8;j++){
- set_xy(x,y+j,ch);
- for(int i=0;i<w;i++){
- //writeI2C(OLEDaddr,DAT,0,(*(char*)(bmp+2+j*w+i+w*(h/8)*elem))^(inv*0xFF),0);
- spi_write(DATA,(*(char*)(bmp+2+j*w+i+w*(h/8)*elem))^(inv*0xFF),ch);
- }
- }
- }
- void drawline(uint8_t x0,uint8_t y0,uint8_t x1,uint8_t y1, bool ch){
- if(abs(y1-y0)<abs(x1-x0)){
- if(x0>x1){
- plotLineLow(x1,y1,x0,y0);
- }else{
- plotLineLow(x0,y0,x1,y1);
- }
- }else{
- if(y0>y1){
- plotLineHigh(x1,y1,x0,y0);
- }else{
- plotLineHigh(x0,y0,x1,y1);
- }
- }
- digitalWrite(9,HIGH);
- drawBMP(0,0,dispbuff,0,NORM,ch);
- digitalWrite(9,LOW);
- }
- void plotLineLow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1){
- char dx=x1-x0;
- char dy=y1-y0;
- char yi=1;
- if(dy<0){
- yi=-1;
- dy=-dy;
- }
- char d=(2*dy)-dx;
- char y=y0;
- for(int x=x0;x<=x1;x++){
- dispbuff[2+x+128*(y/8)]|=1<<(y%8);
- if(d>0){
- y=y+yi;
- d=d+(2*(dy-dx));
- }else{
- d=d+2*dy;
- }
- }
- }
- void plotLineHigh(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1){
- char dx=x1-x0;
- char dy=y1-y0;
- char xi=1;
- if(dx<0){
- xi=-1;
- dx=-dx;
- }
- char d=(2*dx)-dy;
- char x=x0;
- for(int y=y0;y<=y1;y++){
- dispbuff[2+x+128*(y/8)]|=1<<(y%8);
- if(d>0){
- x=x+xi;
- d=d+(2*(dx-dy));
- }else{
- d=d+2*dx;
- }
- }
- }
- void setup() {
- pinMode(LED,OUTPUT);
- pinMode(A0,INPUT);
- pinMode(A1,INPUT);
- pinMode(BTN,INPUT_PULLUP);
- pinMode(Plus,INPUT_PULLUP);
- pinMode(Minus,INPUT_PULLUP);
- Serial.begin(115200);
- SPI.begin();
- SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
- pinMode(RST,OUTPUT);
- pinMode(DC,OUTPUT);
- pinMode(CS0,OUTPUT);
- pinMode(CS1,OUTPUT);
- //pinMode(CK,OUTPUT);
- //pinMode(DA,OUTPUT);
- digitalWrite(CS0,HIGH);
- digitalWrite(CS1,HIGH);
- digitalWrite(RST,HIGH);
- PHYS=EEPROM.read(0);
- if(PHYS>2){PHYS=0;EEPROM.update(0,PHYS);}
- brt=EEPROM.read(1);
- brightness(256-brt);
- dispRST();
- disp_init(Disp0);
- disp_init(Disp1);
- clr(Disp0);
- clr(Disp1);
- set_xy(30,3,Disp0);
- set_xy(30,3,Disp1);
- writeString("VU Meter",Disp0);
- writeString("Version 1.0",Disp1);
- set_xy(30,4,Disp0);
- set_xy(30,4,Disp1);
- writeString("sjm4306",Disp0);
- writeString("C 07/30/21",Disp1);
- delay(2000);
- }
- void loop() {
- clr(Disp0);
- clr(Disp1);
- unsigned int cnt=0;
- unsigned int val0=0,val1=0;
- int pos0=0,pos1=0;
- int err_accum0=0,err_accum1=0;
- int err0=0,err1=0;
- while(1){
- for(int i=0;i<1024;i++){ //transfer background stored in flash to ram display buffer
- dispbuff[i+2]=pgm_read_byte_near(Lbackground+i+2);
- }
- val0=analogRead(A0)/8; //Grab Analog Input Measurement (scaled to 0-127)
- val1=analogRead(A1)/8;
- if(PHYS){
- if(PHYS==1){p_gain=0.2;i_gain=0.8;} //Set gain values for current mode
- if(PHYS==2){p_gain=0.5;i_gain=0.1;}
- err0=val0-pos0; //Calculate Error
- err1=val1-pos1;
- err_accum0+=i_gain*err0; //Calculate PI
- pos0+=(int) (p_gain*err0+err_accum0);
- err_accum1+=i_gain*err1;
- pos1+=(int) (p_gain*err1+err_accum1);
- if(pos0>127){pos0=127;} //max min limiter
- if(pos0<0){pos0=0;}
- if(pos1>127){pos1=127;}
- if(pos1<0){pos1=0;}
- }else{pos0=val0;pos1=val1;}
- drawline(71-(127-pos0)/8,63,pos0,20-(int)(((double)(pos0*(127-pos0)))/200),Disp0); //draw line over background
- for(int i=0;i<1024;i++){ //transfer background stored in flash to ram display buffer
- dispbuff[i+2]=pgm_read_byte_near(Rbackground+i+2);
- }
- drawline(71-(127-pos1)/8,63,pos1,20-(int)(((double)(pos1*(127-pos1)))/200),Disp1);
- if(digitalRead(BTN)==0){
- if(PHYS<2){PHYS++;}else{PHYS=0;}
- EEPROM.update(0,PHYS);
- set_xy(0,7,Disp1);
- if(PHYS==1){
- writeString("U",Disp1);
- }else if(PHYS==2){
- writeString("O",Disp1);
- }else{
- writeString("N",Disp1);
- }
- delay(1000);
- while(digitalRead(BTN)==0){;}
- }
- if(digitalRead(Plus)==0){
- if(brt>1){brt--;EEPROM.update(1,brt);brightness(256-brt);}
- char buff[3];
- set_xy(0,7,Disp0);
- writeString(itoa(256-brt,buff,10),Disp0);
- delay(100);
- }
- if(digitalRead(Minus)==0){
- if(brt<255){brt++;EEPROM.update(1,brt);brightness(256-brt);}
- char buff[3];
- set_xy(0,7,Disp0);
- writeString(itoa(256-brt,buff,10),Disp0);
- delay(100);
- }
- delay(20);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement