// https://forum.arduino.cc/t/i-am-a-complete-beginner-at-programming-and-i-m-trying-to-figure-out-how-to-display-the-data-from-a-xd-58d-onto-a-nokia-3310-screen/1464550
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h> // https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library/blob/master/
Adafruit_PCD8544 display = Adafruit_PCD8544(5, 7, 6); // DC, CS, RST (Hardware SPI - SCK 13, DIN 11)
// https://www.espboards.dev/tools/monochrome-bitmap-tool // monochrome 16x16 bitmap editor
static const unsigned char PROGMEM heart0[] =
{ B00111100, B00111100,
B01000010, B01000010,
B10000001, B10000001,
B10000000, B00000001,
B10000000, B00000001,
B10000000, B00000001,
B10000000, B00000001,
B01000000, B00000010,
B01000000, B00000010,
B00100000, B00000100,
B00100000, B00000100,
B00010000, B00001000,
B00001000, B00010000,
B00000100, B00100000,
B00000010, B01000000,
B00000001, B10000000,
};
static const unsigned char PROGMEM heart1[] =
{ B00000000, B00000000,
B00000000, B00000000,
B00001100, B00110000,
B00010010, B01001000,
B00100001, B10000100,
B00100000, B00000100,
B00100000, B00000100,
B00100000, B00000100,
B00010000, B00001000,
B00010000, B00001000,
B00001000, B00010000,
B00000100, B00100000,
B00000010, B01000000,
B00000001, B10000000,
B00000000, B00000000,
B00000000, B00000000,
};
const int traceWidth = 65, traceDeflection = 8;
int offset_x = 19, offset_y = 33; // trace arrays
int x, y, oldX[traceWidth], oldY[traceWidth], newX[traceWidth], newY[traceWidth]; // trace arrays
unsigned long timer, timeout = 20;
unsigned long hbtimer, hbtimeout = 250;
bool toggle;
void setup() {
// Serial.begin(115200); // start serial comms
display.begin(); // start display instance
display.clearDisplay(); // clears display buffer
display.display(); // show buffer
display.setTextSize(2);
oldX[0] = offset_x;
oldY[0] = offset_y + map(analogRead(A0), 0, 1023, -traceDeflection, traceDeflection);
}
void loop() {
y = map(analogRead(A0), 0, 1023, -8, 8); // new y
if (millis() - timer >= timeout) { // display frequency
timer = millis();
if (x == traceWidth) // restrict x
x = 0; // reset x
displayTemplate(y); // show the template
newX[x] = x + offset_x; // calculate new x position
newY[x] = y + offset_y; // calculate new y position
for (int count = 0; count < x; count++) { // retrace from 0 to current x
// fromX, fromY, toX, toY, color
display.drawLine(oldX[count], oldY[count], newX[count], newY[count], BLACK);
}
display.display(); // display template and retrace
oldX[x] = x + offset_x; // store "this" x in array as oldX
oldY[x] = y + offset_y; // store "this" y in array as oldY
x++; // get new x
}
}
void displayTemplate(int val) { // redraw the 5110 display template
display.clearDisplay();
display.setCursor(5, 5);
display.print(F("PPM:"));
display.setCursor(50, 5);
if (val < 0)
display.print(F("+"));
if (val == 0)
display.print(F("+"));
display.print(-val);
if (millis() - hbtimer >= hbtimeout) {
hbtimer = millis();
toggle = !toggle;
}
if (toggle)
display.drawBitmap(2, 25, heart1, 16, 16, 1); // x, y, bitmap, sizeX, sizeY, color
else
display.drawBitmap(2, 25, heart0, 16, 16, 1); // x, y, bitmap, sizeX, sizeY, color
}Loading
nokia-5110
nokia-5110