Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TRUE 1
- #define FALSE 0
- #define SPI2_NSS_PIN 28
- #include "SPI.h"
- #include "winbondflash.h"
- #include <Adafruit_GFX.h>
- #include <ILI9488.h>
- #include <Average.h>
- HardwareTimer pulseTimer(4);
- // Use hardware SPI (on Uno, #13, #12, #11) and the above for Enable,CS/DC,Reset
- ILI9488 tft = ILI9488(28, PA8 , PB10);
- winbondFlashSPI mem;
- volatile uint16_t pulse_timer_overflow_counter = 0;
- volatile uint32_t lastpulse = 0;
- volatile uint32_t interval = 0;
- volatile float frequency = 0;
- boolean toggle = false;
- int mescount = 0;
- uint32_t cycleinteval = 0;
- Average<float> ave(20);
- uint8_t chartnow[480];
- uint8_t chartlast[480];
- void pulse_isr(void)
- {
- uint32_t current_time = (pulse_timer_overflow_counter << 16) | pulseTimer.getCount();
- if (current_time < lastpulse)
- {
- interval = 0xFFFFFFFF - lastpulse + current_time;
- }
- else
- {
- interval = current_time - lastpulse;
- }
- if (toggle) {
- lastpulse = current_time;
- frequency = (float)(1000000UL / (float)interval);
- if (frequency > 49 && frequency < 51)
- ave.push(frequency);
- toggle = false;
- } else {
- toggle = true;
- }
- }
- uint8_t *buf;
- uint8_t buffarr[8401];
- void setup() {
- buf = buffarr;
- SPI.setBitOrder(MSBFIRST); // Set the SPI_1 bit order
- SPI.setDataMode(SPI_MODE0); //Set the SPI_2 data mode 0
- SPI.setClockDivider(SPI_CLOCK_DIV2);
- pinMode(2, OUTPUT);
- pinMode(3, OUTPUT);
- digitalWrite(2, HIGH);
- digitalWrite(3, HIGH);
- pinMode(4, OUTPUT);
- Serial1.begin(115200);
- tft.begin();
- // SPI.setFrequency(SPI_36MHZ)
- Serial1.println("Init Chip...");
- if (mem.begin(_W25Q64, SPI, 4))
- Serial1.println("OK");
- else
- {
- Serial1.println("FAILED");
- }
- //flash.begin();
- //flash.setClock(16000000);
- pulseTimer.pause();
- pulseTimer.setOverflow(65535);
- pulseTimer.setPrescaleFactor(72);
- pulseTimer.setMode(1, TIMER_OUTPUT_COMPARE);
- pulseTimer.setCompare(1, 65535);
- pulseTimer.attachInterrupt(1, pulse_overflow_isr);
- pulseTimer.refresh();
- pulseTimer.resume();
- pinMode(PB11, INPUT);
- attachInterrupt(PB11, pulse_isr, RISING);
- tft.setRotation(3);
- tft.fillScreen(ILI9488_BLACK);
- uint8_t x = tft.readcommand8(ILI9488_RDMODE);
- //Serial1.print("Display Power Mode: 0x"); //Serial1.println(x, HEX);
- x = tft.readcommand8(ILI9488_RDMADCTL);
- //Serial1.print("MADCTL Mode: 0x"); //Serial1.println(x, HEX);
- x = tft.readcommand8(ILI9488_RDPIXFMT);
- //Serial1.print("Pixel Format: 0x"); //Serial1.println(x, HEX);
- x = tft.readcommand8(ILI9488_RDIMGFMT);
- Serial1.print("Image Format: 0x"); Serial1.println(x, HEX);
- x = tft.readcommand8(ILI9488_RDSELFDIAG);
- String test = "Netzfrequenz";
- drawString(test, 1, 480 / 2 - (12 * 35 / 2), 0);
- drawmyimage(2084300, 0, 0, 480, 320);
- }
- void pulse_overflow_isr(void)
- {
- pulse_timer_overflow_counter++;
- }
- //
- int z = 0;
- int p = 0;
- void loop() {
- memcpy(chartlast, chartnow, 480);
- for (int i = 1; i < 480; i++) {
- chartnow[i - 1] = chartnow[i];
- }
- float floattemp = ave.mean();
- chartnow[479] = map((int)floattemp * 1000, 49700, 50300, 0, 100);
- Serial1.println(chartnow[479]);
- String freq = String(floattemp, 3);
- drawString(freq, 0, 480 / 2 - (12 * 35 / 2), 80);
- delay(200);
- }
- //skalierung
- String oldstring = "";
- void drawString(String mystring, uint8_t fontsize, uint16_t x, uint16_t y )
- {
- int mywidth = 0;
- if (fontsize == 0)
- mywidth = 70;
- else if (fontsize == 1)
- mywidth = 35;
- for (int i = 0; i < mystring.length(); i++)
- {
- char mychar = (char)mystring.charAt(i);
- if (mychar != (char)oldstring.charAt(i))
- drawChar(fontsize, mychar, x + mywidth * i, y);
- }
- oldstring = mystring;
- }
- void drawChar(uint8_t fontsize, char mychar, uint16_t x, uint16_t y) {
- int mywidth, myheight, mysize, frac1, frac2;
- unsigned long startpoint = 0;
- uint8_t ascii = (uint8_t)mychar;
- ascii = ascii - 32;
- // Serial1.println(ascii);
- if (fontsize == 0 || fontsize == 5)
- {
- startpoint = 0;
- mywidth = 70;
- myheight = 119;
- frac1 = 8400;
- frac2 = 8400;
- //Serial1.println("font0");
- }
- else if (fontsize == 1)
- {
- startpoint = 1582700;
- mywidth = 35;
- myheight = 60;
- mem.read(startpoint + (ascii * mywidth * myheight * 2), buf, mywidth * myheight * 2 );
- buf[0] = 0;
- tft.drawImage(buf, x, y, mywidth, myheight );
- } else if (fontsize == 2)
- {
- startpoint = 1981700;
- mywidth = 18;
- myheight = 30;
- }
- mysize = mywidth * myheight;
- uint32_t time1 = 0;
- uint32_t time2 = 0;
- unsigned long timemics = micros();
- if (fontsize == 0)
- {
- mem.read(startpoint + (ascii * mywidth * myheight * 2), buf, frac1 );
- time1 = micros() - timemics;
- buf[0] = 0;
- tft.drawImage(buf, x, y, 70, 60 );
- time2 = micros() - timemics;
- mem.read(startpoint + frac1 + (ascii * mywidth * myheight * 2), buf, frac2);
- buf[0] = 0;
- tft.drawImage(buf, x, y + 59, 70, 59 );
- } else if (fontsize == 5)
- {
- int steps = 10;
- for (int i = 0; i < myheight; i += steps)
- {
- mem.read(startpoint + ((ascii * mywidth * myheight * 2) + i * mywidth * 2), buf, steps * 2 * mywidth );
- buf[0] = 0;
- tft.drawNewImage(buf, x, y + i, 70, steps );
- }
- }
- // Serial1.print(time1);
- // Serial1.print("-");
- // Serial1.println(time2 - time1);
- }
- uint8_t *bufimg = new uint8_t[961];
- void drawmyimage(int startpoint, int x, int y, int picwidth, int picheight) {
- for (int i = 0; i < picheight; i++)
- {
- mem.read(startpoint + (i * picwidth * 2), bufimg, 960);
- buf[0] = 0;
- tft.drawImage(bufimg, 0, y + i, picwidth, 1 );
- }
- }
Add Comment
Please, Sign In to add comment