Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* readADC custom
- * 09Februri2016
- * @bambangSud
- * tepat di ulang tahun pernikahan kami yang ke 38
- * post: 5 Jan 2017
- */
- #define ADC_VREF_TYPE 0x40
- int value;
- float inputVoltage;
- float SUHU;
- // Read the AD conversion result
- unsigned int read_adc(unsigned char adc_input)
- {
- ADMUX = adc_input | (ADC_VREF_TYPE );
- // Delay needed for the stabilization of the ADC input voltage
- delayMicroseconds(10);
- // Start the AD conversion
- ADCSRA |= 0x40;
- // Wait for the AD conversion to complete
- while ((ADCSRA & 0x10) == 0);
- ADCSRA |= 0x10;
- return ADCW;
- }
- void setup() {
- // put your setup code here, to run once:
- ADMUX = ADC_VREF_TYPE & 0xff;
- ADCSRA = 0x84;
- Serial.begin(9600);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- value = read_adc(0);
- delay(100);
- value = read_adc(0);
- inputVoltage = (float)value * 500 / 1023;
- Serial.print("adc0: "); Serial.println(inputVoltage);
- delay(500);
- value = read_adc(1);
- delay(100);
- value = read_adc(1);
- inputVoltage = (float)value * 500 / 1023;
- Serial.print("adc1: "); Serial.println(inputVoltage);
- delay(500);
- value = read_adc(2);
- delay(100);
- value = read_adc(2);
- inputVoltage = (float)value * 500 / 1023;
- Serial.print("adc2: "); Serial.println(inputVoltage);
- Serial.println();
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment