Code Tidy - Pastebin

New     Fork     Embed     View raw     Report

spectrumAnalyzer-pde - cpp

Embed

You can embed this paste into a blog or website with this code:

<iframe class="codetidy" type="text/html" width="100%" src="http://codetidy.com/paste/embed/910" frameborder="0"></iframe>

Add comment

Captcha
  1. #include <rssi.h>?
  2. #include <SPI.h>?
  3.  ?
  4. ///Spectrum analyzer code for Arduino, CYWM6935, and PCD8544 Display.?
  5. ///LCD Functions adapted from http://www.arduino.cc/playground/Code/PCD8544 thanks to the great community there!?
  6. ///CYWM6935 Functions adapted from http://ea4eoz.ure.es/hsa.html thank you as well.?
  7. /////////////////////////////////////////////////////////////////?
  8. // Connections:?
  9. //Arduino pin 8 => Logic Level Translator => CYWM6935 Reset Pin?
  10. //Arduino pin 9 => Logic Level Translator => CYWM6935 SS Pin?
  11. //Arduino pin 11 => Logic Level Translator => CYWM6935 MOSI Pin?
  12. //Arduino pin 12 => CYWM6935 MISO Pin?
  13. //Arduino pin 13 => Logic Level Translator => CYWM6935 SCK Pin?
  14. //Radio PD pin -> 5v?
  15. //Arduino pin 6 => Logic Level Translator => LCD Reset pin?
  16. //Arduino pin 5 => Logic Level Translator => LCD DC pin?
  17. //Arduino pin 4 => Logic Level Translator => LCD SDIN pin?
  18. //Arduino pin 3 => Logic Level Translator => LCD SCLK pin?
  19. /////////////////////////////////////////////////////////////////?
  20.  ?
  21. // LCD Pin Definitions and Variables?
  22. #define PIN_SCE   7  ?
  23. #define PIN_RESET 6  ?
  24. #define PIN_DC    5  ?
  25. #define PIN_SDIN  4?
  26. #define PIN_SCLK  3?
  27. #define LCD_VISIBLE_X_RES   84 ?
  28. #define LCD_C     LOW?
  29. #define LCD_D     HIGH?
  30. #define LCD_X     84?
  31. #define LCD_Y     48?
  32. #define LCD_CMD   0?
  33. #define OUT_OF_BORDER       1?
  34. #define PIXEL_ON  1?
  35. #define PIXEL_OFF   0?
  36. #define MAXCHANNEL 84?
  37. int bottom = 0;?
  38.  ?
  39. #define MODECOUNT 5?
  40. int buttonPin = 2;  // Mode-Changing Button?
  41. volatile int mode; //1 is normal, 2 is digital (stepping) mode, 3 is exposure mode?
  42. char signal[MAXCHANNEL];?
  43. unsigned char n=0;?
  44. int Lcd_TOP = 40;?
  45. int Lcd_visible = Lcd_TOP - bottom;?
  46. volatile bool toggled = 0;?
  47. rssi radio;?
  48.  ?
  49. void setup() {?
  50.   pinMode(buttonPin, INPUT);    // button as input?
  51.   digitalWrite(buttonPin, HIGH); // turns on pull-up resistor after input?
  52.   // Hardware initialization?
  53.  ?
  54.  ?
  55.   LcdInitialise();?
  56.   LcdClear();?
  57.   radio.RADIO_Init();?
  58.   attachInterrupt(0, toggle, FALLING);?
  59.   mode = 1;?
  60.  ?
  61. }?
  62. void loop() {?
  63.   if(toggled)?
  64.   {?
  65.     switchmode();?
  66.   }?
  67.   if (mode == 1)?
  68.   {?
  69.  ?
  70.  ?
  71.     gotoXY(75,5);?
  72.     LcdCharacter('F');?
  73.     gotoXY(69,5);?
  74.     LcdCharacter('a');?
  75.     gotoXY(63,5);?
  76.     LcdCharacter('s');?
  77.  ?
  78.     gotoXY(57,5);?
  79.     LcdCharacter('t');?
  80.  ?
  81.     gotoXY(51,5);?
  82.     LcdCharacter(' ');?
  83.     gotoXY(45,5);?
  84.     LcdCharacter('S');?
  85.     gotoXY(39,5);?
  86.     LcdCharacter('c');?
  87.  ?
  88.     gotoXY(33,5);?
  89.     LcdCharacter('a');?
  90.  ?
  91.     gotoXY(27,5);?
  92.     LcdCharacter('n');?
  93.  ?
  94.  ?
  95.     // Read signals?
  96.     for (unsigned char n=0; n<MAXCHANNEL; n++){?
  97.       // Read the signal on current channel?
  98.       unsigned char s = radio.RADIO_RSSI(n);?
  99.       s = map(s, 0, 31, 0,Lcd_visible); ?
  100.       signal[n]=s;?
  101.     }?
  102.     for (unsigned char n = LCD_VISIBLE_X_RES; n > 0; n--){?
  103.       drawLine(n,Lcd_TOP,PIXEL_OFF);?
  104.       drawLine(n,signal[abs(LCD_VISIBLE_X_RES-n)], PIXEL_ON);?
  105.  ?
  106.     }?
  107.   }?
  108.  ?
  109.   else if (mode == 2)?
  110.   {?
  111.  ?
  112.     gotoXY(75,5);?
  113.     LcdCharacter('S');?
  114.     gotoXY(69,5);?
  115.     LcdCharacter('l');?
  116.     gotoXY(63,5);?
  117.     LcdCharacter('o');?
  118.  ?
  119.     gotoXY(57,5);?
  120.     LcdCharacter('w');?
  121.  ?
  122.     gotoXY(51,5);?
  123.     LcdCharacter(' ');?
  124.     gotoXY(45,5);?
  125.     LcdCharacter('S');?
  126.     gotoXY(39,5);?
  127.     LcdCharacter('c');?
  128.  ?
  129.     gotoXY(33,5);?
  130.     LcdCharacter('a');?
  131.  ?
  132.     gotoXY(27,5);?
  133.     LcdCharacter('n');?
  134.  ?
  135.     // Read signals?
  136.     for (unsigned char n=0; n<MAXCHANNEL; n++){?
  137.       // Read the signal on current channel?
  138.       unsigned char s = radio.RADIO_RSSI(n);?
  139.       s = map(s, 0, 31, 0,Lcd_visible); ?
  140.       if(s < signal[n])?
  141.       {?
  142.         signal[n] = signal[n]-1;?
  143.       }?
  144.       else {?
  145.         signal[n]=s;?
  146.       }?
  147.     }?
  148.     for (unsigned char n = LCD_VISIBLE_X_RES; n > 0; n--){?
  149.       drawLine(n,Lcd_TOP,PIXEL_OFF);?
  150.       drawLine(n,signal[abs(LCD_VISIBLE_X_RES-n)], PIXEL_ON);?
  151.  ?
  152.     }?
  153.   }?
  154.   else if (mode == 3)?
  155.   {?
  156.  ?
  157.     gotoXY(75,5);?
  158.     LcdCharacter('G');?
  159.     gotoXY(69,5);?
  160.     LcdCharacter('h');?
  161.     gotoXY(63,5);?
  162.     LcdCharacter('o');?
  163.  ?
  164.     gotoXY(57,5);?
  165.     LcdCharacter('s');?
  166.  ?
  167.     gotoXY(51,5);?
  168.     LcdCharacter('t');?
  169.     gotoXY(45,5);?
  170.     LcdCharacter(' ');?
  171.     gotoXY(39,5);?
  172.     LcdCharacter('S');?
  173.  ?
  174.     gotoXY(33,5);?
  175.     LcdCharacter('c');?
  176.  ?
  177.     gotoXY(27,5);?
  178.     LcdCharacter('a');?
  179.  ?
  180.     gotoXY(21,5);?
  181.     LcdCharacter('n');?
  182.     // Read signals?
  183.     for (unsigned char n=0; n<MAXCHANNEL; n++){?
  184.       // Read the signal on current channel?
  185.       unsigned char s = radio.RADIO_RSSI(n);?
  186.       s = map(s, 0, 31, 0,Lcd_visible); ?
  187.       if(s < signal[n])?
  188.       {?
  189.         signal[n] = signal[n];?
  190.       }?
  191.       else {?
  192.         signal[n]=s;?
  193.       }?
  194.     }  ?
  195.     for (unsigned char n = LCD_VISIBLE_X_RES; n > 0; n--){?
  196.       drawLine(n,Lcd_TOP,PIXEL_OFF);?
  197.       drawLine(n,signal[abs(LCD_VISIBLE_X_RES-n)], PIXEL_ON);?
  198.  ?
  199.     }?
  200.  ?
  201.   }?
  202.   else if (mode == 4)?
  203.   {?
  204.  ?
  205.     gotoXY(75,5);?
  206.     LcdCharacter('V');?
  207.     gotoXY(69,5);?
  208.     LcdCharacter('o');?
  209.     gotoXY(63,5);?
  210.     LcdCharacter('l');?
  211.  ?
  212.     gotoXY(57,5);?
  213.     LcdCharacter('t');?
  214.  ?
  215.     gotoXY(51,5);?
  216.     LcdCharacter('m');?
  217.     gotoXY(45,5);?
  218.     LcdCharacter('e');?
  219.     gotoXY(39,5);?
  220.     LcdCharacter('t');?
  221.  ?
  222.     gotoXY(33,5);?
  223.     LcdCharacter('e');?
  224.  ?
  225.     gotoXY(27,5);?
  226.     LcdCharacter('r');?
  227.  ?
  228.     gotoXY(21,5);?
  229.     LcdCharacter('(');?
  230.  ?
  231.     gotoXY(15,5);?
  232.     LcdCharacter('A');?
  233.  ?
  234.     gotoXY(9,5);?
  235.     LcdCharacter('5');?
  236.  ?
  237.     gotoXY(3,5);?
  238.     LcdCharacter(')');?
  239.  ?
  240.  ?
  241.     int aread = analogRead(5);?
  242.     float readval = (float)aread / 1023.0;?
  243.     readval = readval * 5.0;?
  244.     readval = readval * 100.0;?
  245.     int finalval = int(readval);?
  246.     char buffer [3] = {?
  247.       0, 0, 0            };?
  248.     itoa (finalval,buffer,10);?
  249.  ?
  250.     gotoXY(50,3);?
  251.     LcdCharacter(buffer[0]);?
  252.  ?
  253.     gotoXY(44,3);?
  254.     LcdCharacter('.');?
  255.  ?
  256.     gotoXY(38,3);?
  257.     LcdCharacter(buffer[1]);?
  258.  ?
  259.     gotoXY(32,3);?
  260.     LcdCharacter(buffer[2]);?
  261.     delay(500);?
  262.  ?
  263.   }?
  264.  ?
  265.   else if (mode == 5)?
  266.   {?
  267.     toggled = 0;?
  268.     gotoXY(75,5);?
  269.     LcdCharacter('M');?
  270.     gotoXY(69,5);?
  271.     LcdCharacter('i');?
  272.     gotoXY(63,5);?
  273.     LcdCharacter('n');?
  274.  ?
  275.     gotoXY(57,5);?
  276.     LcdCharacter('i');?
  277.  ?
  278.     gotoXY(51,5);?
  279.     LcdCharacter('-');?
  280.     gotoXY(45,5);?
  281.     LcdCharacter('S');?
  282.     gotoXY(39,5);?
  283.     LcdCharacter('c');?
  284.  ?
  285.     gotoXY(33,5);?
  286.     LcdCharacter('o');?
  287.  ?
  288.     gotoXY(27,5);?
  289.     LcdCharacter('p');?
  290.  ?
  291.     gotoXY(21,5);?
  292.     LcdCharacter('e');?
  293.  ?
  294.     gotoXY(15,5);?
  295.     LcdCharacter(' ');?
  296.  ?
  297.     gotoXY(9,5);?
  298.     LcdCharacter('A');?
  299.  ?
  300.     gotoXY(3,5);?
  301.     LcdCharacter('5');?
  302.  ?
  303.     for (unsigned char n = LCD_VISIBLE_X_RES; n > 0; n--){?
  304.  ?
  305.       drawLine(n,Lcd_TOP,PIXEL_OFF);?
  306.       int mappedval = map(analogRead(5), 0, 1023, 0,Lcd_visible); ?
  307.       drawLine(n,mappedval,PIXEL_ON);?
  308.  ?
  309.  ?
  310.     }?
  311.  ?
  312.  ?
  313.     delay(10);?
  314.   }?
  315. }?
  316. void switchmode()?
  317. {?
  318.   toggled = 0;?
  319.   LcdClear();?
  320.   if(mode == MODECOUNT)?
  321.   {?
  322.     mode = 1;?
  323.   }?
  324.   else?
  325.   {?
  326.     mode++;?
  327.   }?
  328.  ?
  329. }?
  330. void toggle()?
  331. {?
  332.   toggled = 1;?
  333.  ?
  334. }?
© 2011 Code Tidy