sources and files for the bombatuino project
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.

42 lines
943 B

  1. int tolerance = 4;
  2. const int s0 = 10;
  3. const int s1 = 9;
  4. const int s2 = 8;
  5. int pots[] = {-1,-1};
  6. void setup() {
  7. Serial.begin(9600);
  8. pinMode(s0,OUTPUT);
  9. pinMode(s1,OUTPUT);
  10. pinMode(s2,OUTPUT);
  11. }
  12. void loop() {
  13. //get Y0 of 4051
  14. digitalWrite(s0, LOW);
  15. digitalWrite(s1, LOW);
  16. digitalWrite(s1, LOW);
  17. int read = analogRead(A1);
  18. //only print value on change (tolerance of 4 out of 1024)
  19. if (pots[0] < read - tolerance || pots[0] > read + tolerance) {
  20. pots[0] = read;
  21. Serial.print("pot 0: ");
  22. //print value between 0 & 127 like MIDI velocity ;)
  23. Serial.print(pots[0]/8);
  24. Serial.println();
  25. }
  26. //get Y1 of 4051, analog to Y0
  27. digitalWrite(s0, HIGH);
  28. digitalWrite(s1, LOW);
  29. digitalWrite(s1, LOW);
  30. read = analogRead(A1);
  31. if (pots[1] < read - tolerance || pots[1] > read + tolerance) {
  32. pots[1] = read;
  33. Serial.print("pot 1: ");
  34. Serial.print(pots[1]/8);
  35. Serial.println();
  36. }
  37. }