leo3065

Arduino LCD 5110 Testing

Jun 26th, 2016
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Adafruit_GFX.h>
  3. #include <Adafruit_PCD8544.h>
  4.  
  5. #define Pi 3.1415926535
  6. #define Deg *Pi/180
  7.  
  8. // Using 3.3 volts power
  9. // Software SPI (slower updates, more flexible pin options):
  10. // pin 22 - Serial clock out (SCLK)
  11. // pin 23 - Serial data out (DIN)
  12. // pin 24 - Data/Command select (D/C)
  13. // pin 25 - LCD chip select (CS)
  14. // pin 26 - LCD reset (RST)
  15. Adafruit_PCD8544 display = Adafruit_PCD8544(22, 23, 24, 25, 26);
  16. int height = display.height();
  17. int width = display.width();
  18. int count = 0;
  19.  
  20. void setup()   {
  21.   Serial.begin(9600);
  22.  
  23.   // init
  24.   display.begin();
  25.   display.setContrast(50);
  26.   display.setTextSize(1);
  27.   display.setTextColor(BLACK);
  28.   display.setRotation(2); // because in this example we're using it upside down
  29.   display.setCursor(0,0);
  30.   display.clearDisplay();
  31.   display.display();
  32. }
  33.  
  34.  
  35. void loop() {
  36.   float r = min(height,width)/2-1;
  37.   float theta = (float(count)*6-90) Deg;
  38.   int x1 = int((r-2)*cos(theta)+width/2);
  39.   int y1 = int((r-2)*sin(theta)+height/2);
  40.   int x2 = int((r-7)*cos(theta+12 Deg)+width/2);
  41.   int y2 = int((r-7)*sin(theta+12 Deg)+height/2);
  42.   int x3 = int((r-7)*cos(theta-12 Deg)+width/2);
  43.   int y3 = int((r-7)*sin(theta-12 Deg)+height/2);
  44.   Serial.println(count);
  45.   display.clearDisplay();
  46.   display.setCursor(0,0);
  47.   display.println(count);
  48.   display.drawCircle(width/2, height/2, int(r), BLACK);
  49.   display.drawLine(width/2, height/2, x1, y1, BLACK);
  50.   display.fillTriangle(x1 ,y1, x2, y2, x3, y3, BLACK);
  51.   display.display();
  52.   delay(200);
  53.   count=(count+1)%60;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment