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
965 B

  1. /*
  2. Morse.cpp - Library for flashing Morse code.
  3. Created by David A. Mellis, November 2, 2007.
  4. Released into the public domain.
  5. */
  6. #include "Arduino.h"
  7. #include "input_4051.h"
  8. const int tolerance = 4;
  9. input_4051::input_4051(int analogPin, int s0Pin, int s1Pin, int s2Pin, void (*valueChangeCallback(int,int)))
  10. {
  11. _analog = analogPin;
  12. _s0 = s0Pin;
  13. _s1 = s1Pin;
  14. _s2 = s2Pin;
  15. pinMode(_analog,INPUT);
  16. pinMode(_s0,OUTPUT);
  17. pinMode(_s1,OUTPUT);
  18. pinMode(_s2,OUTPUT);
  19. _valueChangeCallback = valueChangeCallback;
  20. _value = {-1,-1,-1,-1,-1,-1,-1,-1};
  21. }
  22. void input_4051::loop()
  23. {
  24. for (count=0; count<=7; count++) {
  25. r0 = bitRead(count,0);
  26. r1 = bitRead(count,1);
  27. r2 = bitRead(count,2);
  28. digitalWrite(_s0, r0);
  29. digitalWrite(_s1, r1);
  30. digitalWrite(_s2, r2);
  31. int read = analogRead(_analog);
  32. if (value[count] < read - tolerance || value[count] > read + tolerance) {
  33. value[count] = read;
  34. _valueChangeCallback(count, read);
  35. }
  36. }
  37. }