Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ANREDEFT 120
- #define SENDSERIALDELAY 1000
- uint8_t enableAnalogReadA1 = 1;
- uint32_t previousMillisAnalogReadA1 = 0;
- uint32_t intervalAnalogReadA1 = ANREDEFT; // ANALOG_READ_A1_DFT_DELAY;
- uint16_t currAnaReadVal=0;
- uint32_t previousMillisSendStatusSerial = 0;
- uint32_t intervalSendStatusSerial = SENDSERIALDELAY; // ANALOG_READ_A1_DFT_DELAY;
- void setup()
- {
- ADCSRA = bit(ADEN) // Turn ADC on
- | bit(ADPS0) | bit(ADPS1) | bit(ADPS2); // Prescaler of 128
- ADMUX = bit(REFS0) // AVCC
- | ((1) & 0x07); // Arduino Uno to ADC pin 1=A1 , 0= A0 etc.
- // initiate getting value first time now
- bitSet(ADCSRA, ADSC);
- Serial.begin(9600);
- }
- void loop()
- {
- unsigned long nowStamp = millis();
- //stop the loop to read the analog value requested and request a new read
- if (enableAnalogReadA1 && (nowStamp - previousMillisAnalogReadA1 >= intervalAnalogReadA1))
- {
- if (bit_is_clear(ADCSRA, ADSC))
- {
- currAnaReadVal = ADC;
- bitSet(ADCSRA, ADSC); // request new read
- previousMillisAnalogReadA1 = nowStamp; // set timer
- intervalAnalogReadA1 = ANREDEFT; // aplicable if intervalAnalogReadA1 changed
- }
- else
- {
- intervalAnalogReadA1 += 30; // give it an extra 30 ms to clear.
- // Probably useless, Should never take longer than the hw dft 120ms
- }
- }
- //stop the loop to send the temperature to the serial port every SENDSERIALDELAY
- if (nowStamp - previousMillisSendStatusSerial >= intervalSendStatusSerial)
- {
- previousMillisSendStatusSerial += intervalSendStatusSerial;
- Serial.print("Current A1 value is : ");
- Serial.println(currAnaReadVal,DEC);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement