Advertisement
ha7at

villam

Apr 24th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. define FASTADC 1
  2.  
  3. // defines for setting and clearing register bits
  4. #ifndef cbi
  5. #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
  6. #endif
  7. #ifndef sbi
  8. #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
  9. #endif
  10.  
  11.  
  12. int data = 512;
  13. int storage[512];
  14.  
  15. long batchStarted;
  16. long batchEnded;
  17. int reading;
  18. int count;
  19. int maximum;
  20. int minimum;
  21. bool toSend;
  22.  
  23. void setup() {
  24. #if FASTADC
  25. // set prescale to 16
  26. sbi(ADCSRA,ADPS2) ;
  27. cbi(ADCSRA,ADPS1) ;
  28. cbi(ADCSRA,ADPS0) ;
  29. #endif
  30. // put your setup code here, to run once:
  31. Serial.begin(9600);
  32. pinMode(A5,INPUT);
  33. Serial.println(micros());
  34.  
  35. batchStarted=0;
  36. batchEnded=0;
  37. reading=0;
  38. count=0;
  39. maximum=0;
  40. minimum=1023;
  41. toSend=false;
  42. }
  43.  
  44.  
  45. void loop() {
  46. // put your main code here, to run repeatedly:
  47. reading = (analogRead(A5));
  48. storage[count]=reading;
  49. if ((!toSend)&&(count!=0)&&((reading>storage[count-1]+10)||(reading<storage[count-1]-10))){
  50. toSend=true;
  51. }
  52.  
  53. count=count+1;
  54. if ((count == 512) && (toSend))
  55. {
  56. count=0;
  57. batchEnded = millis();
  58. sendData();
  59. batchStarted = millis();
  60.  
  61. }
  62. else if (count==512){
  63. count=0;
  64. batchEnded = millis();
  65. //sendData();
  66. batchStarted = millis();
  67.  
  68. }
  69.  
  70.  
  71. }
  72.  
  73. void sendData()
  74. {
  75. //Serial.print(">>>");
  76. //Serial.println(batchStarted);
  77.  
  78. for (int i=0;i<data;i++){
  79. Serial.println(storage[i]);
  80. }
  81. //Serial.print("<<<");
  82. //Serial.println(batchEnded);
  83. //Serial.println("END");
  84.  
  85. toSend=false;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement