Guest User

Maple XAdc: main.cpp

a guest
May 27th, 2011
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include "wirish.h"
  2. #include "xadc.h"
  3.  
  4. uint16 adcbuf[2000];
  5. uint8 linebuf[80];
  6. XAdc xadc;
  7.  
  8.  
  9. void dumpline(uint16 value, uint8 p){
  10.     uint8 pos=(p) ? (38):(1);
  11.     for(int j=0;j<35;j++) {
  12.         if(j<(value*36)/4096) linebuf[pos+1+j]= (p) ? ('#'):(' ');
  13.         else linebuf[pos+1+j]=(p) ? (' '):('#');
  14.     }
  15. }
  16.  
  17.  
  18. void setup() {
  19.     //Setup XAdc
  20.     xadc.set_options(2,0,XAdc::Dual,XAdc::Blocking,adcbuf);
  21.     xadc.set_sample_rate(XADC_SAMPLE_RATE_55kHz);
  22.  
  23.     //led
  24.     pinMode(BOARD_LED_PIN, OUTPUT);
  25.    
  26.     //pin6 on and off
  27.     pinMode(6,OUTPUT);
  28.    
  29.     //pin 7 always on
  30.     pinMode(7,OUTPUT);
  31.     digitalWrite(7,HIGH);
  32.  
  33.     //init linebuf
  34.     linebuf[0]=linebuf[38]='[';
  35.     linebuf[37]=linebuf[77]=']';
  36.     linebuf[78]='\r';
  37.     linebuf[79]='\n';
  38. }
  39.  
  40. void loop(){
  41.     xadc.read(100);
  42.     for(int i=0;i<100;i++) {
  43.         dumpline(adcbuf[i],i%2);
  44.         SerialUSB.write(linebuf,80);
  45.     }
  46.     toggleLED();
  47.     togglePin(6);
  48.     delay(100);
  49. }
  50.  
  51.  
  52. // Force init to be called *first*, i.e. before static object allocation.
  53. // Otherwise, statically allocated objects that need libmaple may fail.
  54. __attribute__((constructor)) void premain() {
  55.     init();
  56. }
  57.  
  58. int main(void) {
  59.     setup();
  60.  
  61.     while (1) {
  62.         loop();
  63.     }
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment