You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

  1. /*
  2. DigitalReadSerial
  3. Reads a digital input on pin 2, prints the result to the serial monitor
  4. This example code is in the public domain.
  5. */
  6. int ADC_VAL0 = A0;
  7. // the setup routine runs once when you press reset:
  8. void setup() {
  9. // initialize serial communication at 9600 bits per second:
  10. Serial.begin(9600);
  11. // make the ADC_VAL0's pin an input:
  12. //pinMode(ADC_VAL0, INPUT);
  13. analogReference(INTERNAL);
  14. //to find where arduino does this, grep -r analogReference in Arduino install folder
  15. //cryptic shit though
  16. //so instead, just fprint the register before and after the change. much more intuitive.
  17. //do it manually...
  18. //this doesn't work
  19. //ADMUX = (0 << REFS1) | (0 << REFS0) ;
  20. //this doesn't work
  21. //ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX0);
  22. //this doesn't work
  23. //ADMUX = ADMUX | 0b11001110;
  24. //this doesn't work
  25. //ADMUX = (1 << REFS1) | (1 << REFS0) ;
  26. //this also doesn't work
  27. //ADMUX |= (1 << REFS0);
  28. //ADMUX |= (1 << REFS1);
  29. //search engines have been fucked over with endless forum debates, hopeless. a blog post guide would suffice.
  30. //even this doesn't work. why... it should work. must be wiring code breaking things. give up for now.
  31. //ADMUX = ADMUX | 0b11000000;
  32. }
  33. // the loop routine runs over and over again forever:
  34. void loop() {
  35. // read the input pin:
  36. int ADCVAL0_State = analogRead(ADC_VAL0);
  37. // print out the state of the button:
  38. Serial.println(ADCVAL0_State);
  39. delay(10000); // delay in between reads for stability
  40. //Trying to debug why I cant change a bit in a register. fucking wiring. fuck search engines.
  41. //int dog = ADMUX;
  42. //Serial.println(ADMUX,BIN);
  43. }