bambangSud

Read ADC 3 channel

Jan 5th, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /* readADC custom
  2. * 09Februri2016
  3. * @bambangSud
  4. * tepat di ulang tahun pernikahan kami yang ke 38
  5. * post: 5 Jan 2017
  6. */
  7.  
  8.  
  9.  
  10.  
  11. #define ADC_VREF_TYPE 0x40
  12. int value;
  13. float inputVoltage;
  14. float SUHU;
  15. // Read the AD conversion result
  16. unsigned int read_adc(unsigned char adc_input)
  17. {
  18. ADMUX = adc_input | (ADC_VREF_TYPE );
  19. // Delay needed for the stabilization of the ADC input voltage
  20. delayMicroseconds(10);
  21. // Start the AD conversion
  22. ADCSRA |= 0x40;
  23. // Wait for the AD conversion to complete
  24. while ((ADCSRA & 0x10) == 0);
  25. ADCSRA |= 0x10;
  26. return ADCW;
  27. }
  28.  
  29. void setup() {
  30. // put your setup code here, to run once:
  31. ADMUX = ADC_VREF_TYPE & 0xff;
  32. ADCSRA = 0x84;
  33. Serial.begin(9600);
  34. }
  35.  
  36. void loop() {
  37. // put your main code here, to run repeatedly:
  38. value = read_adc(0);
  39. delay(100);
  40. value = read_adc(0);
  41. inputVoltage = (float)value * 500 / 1023;
  42. Serial.print("adc0: "); Serial.println(inputVoltage);
  43. delay(500);
  44.  
  45. value = read_adc(1);
  46. delay(100);
  47. value = read_adc(1);
  48. inputVoltage = (float)value * 500 / 1023;
  49. Serial.print("adc1: "); Serial.println(inputVoltage);
  50. delay(500);
  51.  
  52. value = read_adc(2);
  53. delay(100);
  54. value = read_adc(2);
  55. inputVoltage = (float)value * 500 / 1023;
  56. Serial.print("adc2: "); Serial.println(inputVoltage);
  57. Serial.println();
  58.  
  59. delay(1000);
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment