Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "wirish.h"
- #include "xadc.h"
- uint16 adcbuf[2000];
- uint8 linebuf[80];
- XAdc xadc;
- void dumpline(uint16 value, uint8 p){
- uint8 pos=(p) ? (38):(1);
- for(int j=0;j<35;j++) {
- if(j<(value*36)/4096) linebuf[pos+1+j]= (p) ? ('#'):(' ');
- else linebuf[pos+1+j]=(p) ? (' '):('#');
- }
- }
- void setup() {
- //Setup XAdc
- xadc.set_options(2,0,XAdc::Dual,XAdc::Blocking,adcbuf);
- xadc.set_sample_rate(XADC_SAMPLE_RATE_55kHz);
- //led
- pinMode(BOARD_LED_PIN, OUTPUT);
- //pin6 on and off
- pinMode(6,OUTPUT);
- //pin 7 always on
- pinMode(7,OUTPUT);
- digitalWrite(7,HIGH);
- //init linebuf
- linebuf[0]=linebuf[38]='[';
- linebuf[37]=linebuf[77]=']';
- linebuf[78]='\r';
- linebuf[79]='\n';
- }
- void loop(){
- xadc.read(100);
- for(int i=0;i<100;i++) {
- dumpline(adcbuf[i],i%2);
- SerialUSB.write(linebuf,80);
- }
- toggleLED();
- togglePin(6);
- delay(100);
- }
- // Force init to be called *first*, i.e. before static object allocation.
- // Otherwise, statically allocated objects that need libmaple may fail.
- __attribute__((constructor)) void premain() {
- init();
- }
- int main(void) {
- setup();
- while (1) {
- loop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment