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.

94 lines
2.0 KiB

3 years ago
  1. #define hzclk 7
  2. #define hzbinary 6
  3. #define sigLED 11
  4. uint8_t hzclkval = 0;
  5. uint8_t hzbinval[30];
  6. uint8_t clkval = 0;
  7. uint32_t milliscompare = 0;
  8. uint8_t readyet = 0;
  9. uint8_t x = 0;
  10. void setup() {
  11. // put your setup code here, to run once:
  12. pinMode(hzclk, INPUT);
  13. pinMode(hzbinary, INPUT);
  14. pinMode(sigLED, OUTPUT);
  15. Serial.begin(115200);
  16. }
  17. void loop() {
  18. if(digitalRead(hzbinary) == LOW){
  19. //this handles one clk cycle each
  20. //need to read 20 cycles
  21. clkval = 0;
  22. checkCLKandBIN();checkCLKandBIN();checkCLKandBIN();
  23. checkCLKandBIN();checkCLKandBIN();checkCLKandBIN();
  24. checkCLKandBIN();checkCLKandBIN();checkCLKandBIN();
  25. checkCLKandBIN();checkCLKandBIN();checkCLKandBIN();
  26. checkCLKandBIN();checkCLKandBIN();checkCLKandBIN();
  27. checkCLKandBIN();
  28. checkCLKandBIN();
  29. checkCLKandBIN();
  30. checkCLKandBIN();
  31. checkCLKandBIN();
  32. }
  33. delayMicroseconds(100); //must be lower than 1 millisecond, so mic
  34. /*if hzbinary is low
  35. *
  36. * while clk high, do nothing
  37. * clk++
  38. * sample hzbinary
  39. * while clk low do nothing
  40. */
  41. /*
  42. * //serial print is very slow, and breaks timing
  43. * the below is not usable
  44. * (DMA anyone? second processor anyone?)
  45. Serial.println("hzbinval 1 - 20:");
  46. for(x=0;x<21;x++){
  47. Serial.println(hzbinval[x]);
  48. }
  49. Serial.print("\n\n\n\n");
  50. */
  51. //sample on falling edge (middle of bit)
  52. }
  53. void checkCLKandBIN(void){
  54. /*
  55. * while clk high, do nothing
  56. * clk++
  57. * sample hzbinary
  58. * while clk low do nothing
  59. */
  60. //milliscompare = millis();
  61. while((hzclkval = digitalRead(hzclk)) == HIGH){
  62. if(readyet == 0){
  63. hzbinval[clkval] = digitalRead(hzbinary);
  64. clkval++;
  65. readyet = 1;
  66. }
  67. delayMicroseconds(10);
  68. }
  69. while((hzclkval = digitalRead(hzclk)) == LOW){
  70. delayMicroseconds(1);
  71. readyet = 0;
  72. }
  73. digitalWrite(sigLED, HIGH);
  74. delayMicroseconds(1);
  75. digitalWrite(sigLED, LOW);
  76. //would be nice to add a picture to this source code (waveform)
  77. //or oscope picture
  78. //why isn't this possible?
  79. }