SHARE
TWEET

Untitled

a guest May 22nd, 2014 2,913 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_GFX.h>
  2. #include <Adafruit_PCD8544.h>
  3. #include <SPI.h>
  4.  
  5. #define DISPLAY_WIDTH 84
  6. #define DISPLAY_HEIGHT 48
  7.  
  8. #define ARDUINO_PRECISION 1023.0
  9. Adafruit_PCD8544 display = Adafruit_PCD8544(10, 5, 3);
  10.  
  11. //Analog Pins
  12. int channelAI = A0;      // probe
  13.  
  14. //#define DELAY_POTENTIMETER //disabled it I don't have it connected
  15. #ifdef DELAY_POTENTIMETER
  16. int delayAI = A1;       // delay potentiometer
  17. #endif
  18.  
  19. float delayVariable = 0;
  20. float scale = 0;
  21. int xCounter = 0;
  22. int yPosition = 0;
  23. int readings[DISPLAY_WIDTH+1];
  24. int counter = 0;
  25.  
  26. unsigned long drawtime = 0;
  27. unsigned long lastdraw = 0;
  28. int frames = 0;
  29.  
  30. void setup(void)
  31. {
  32.   display.begin();
  33.   display.setContrast(30);// you might have a slightly different display so it might not be the optimal value for you
  34.   display.clearDisplay();
  35. }
  36.  
  37. void loop()
  38. {  
  39.   #ifdef DELAY_POTENTIMETER
  40.   delayVariable = analogRead(delayAI);
  41.   delayVariable = (delayVariable/10);
  42.   #endif
  43.   scale = (float)(DISPLAY_HEIGHT-1)/ARDUINO_PRECISION;
  44.  
  45.   //record readings
  46.   for(xCounter = 0; xCounter <= DISPLAY_WIDTH; xCounter++)
  47.   {                                
  48.     yPosition = analogRead(channelAI);
  49.     readings[xCounter] = (yPosition*scale);
  50.     #ifdef DELAY_POTENTIMETER
  51.     delay (delayVariable);
  52.     #endif
  53.   }
  54.  
  55.   display.clearDisplay();
  56.  
  57.   //Draw Voltage Ref Lines
  58.   display.drawLine( 10, 0, 10, DISPLAY_HEIGHT-1, BLACK);
  59.   display.drawLine( 5, (DISPLAY_HEIGHT-1)-(.2 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.2 *ARDUINO_PRECISION * scale), BLACK);
  60.   display.drawLine( 0, (DISPLAY_HEIGHT-1)-(.4 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.4 *ARDUINO_PRECISION * scale), BLACK);
  61.   display.drawLine( 5, (DISPLAY_HEIGHT-1)-(.6 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.6 *ARDUINO_PRECISION * scale), BLACK);
  62.   display.drawLine( 0, (DISPLAY_HEIGHT-1)-(.8 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.8 *ARDUINO_PRECISION * scale), BLACK);
  63.   //display.drawLine( 5, (DISPLAY_HEIGHT-1)-(.84 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.84 *ARDUINO_PRECISION * scale), BLACK);
  64.  
  65.   //Draw Voltage Ref Numbers
  66.   display.setCursor(0,((DISPLAY_HEIGHT-1)-(.2 *ARDUINO_PRECISION * scale))-3);
  67.   display.print((int)(5.0*0.2));
  68.   display.setCursor(0,((DISPLAY_HEIGHT-1)-(.4 *ARDUINO_PRECISION * scale))-3);
  69.   display.print((int)(5.0*0.4));
  70.   display.setCursor(0,((DISPLAY_HEIGHT-1)-(.6 *ARDUINO_PRECISION * scale))-3);
  71.   display.print((int)(5.0*0.6));
  72.   display.setCursor(0,((DISPLAY_HEIGHT-1)-(.8 *ARDUINO_PRECISION * scale))-3);
  73.   display.print((int)(5.0*0.8));
  74.  
  75.   for(xCounter = 0; xCounter <= DISPLAY_WIDTH; xCounter++)
  76.   {
  77.     display.drawPixel(xCounter, (DISPLAY_HEIGHT-1)-readings[xCounter], BLACK);
  78.     if(xCounter>1){
  79.       display.drawLine(xCounter-1, (DISPLAY_HEIGHT-1)-readings[xCounter-1], xCounter, (DISPLAY_HEIGHT-1)-readings[xCounter], BLACK);
  80.     }
  81.   }
  82.   //Draw FPS
  83.   display.setCursor((DISPLAY_WIDTH-1)-11,0);
  84.   display.print(frames);
  85.  
  86.   //Draw Voltage
  87.   display.setCursor(((DISPLAY_WIDTH-1)/2),0);
  88.   display.print(analogRead(channelAI)/ARDUINO_PRECISION*5.0);
  89.  
  90.   display.display();
  91.  
  92.   //Calculate FPS
  93.   drawtime = micros();
  94.   frames=1000000/*a second*//(drawtime-lastdraw);
  95.   lastdraw = drawtime;
  96. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top