Schupp

7seg pressure esp32

Jan 6th, 2022
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. #include <ESP32Encoder.h>
  2. #include "BluetoothSerial.h"
  3.  
  4. #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
  5. #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
  6. #endif
  7.  
  8. BluetoothSerial SerialBT;
  9.  
  10. ESP32Encoder encoder;
  11.  
  12. // set the 7segment type (common Cathode or Anode)
  13. const bool commonCathode = true; // I'm using common Cathode 7segment if you use common Anode then change the value into false.
  14. // alpha-digit pattern for a 7-segment display
  15. const byte digit_pattern[17] =
  16. {
  17. // 74HC595 Outpin Connection with 7segment display.
  18. // Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7
  19. // a b c d e f g DP
  20. 0b11111100, // 0
  21. 0b01100000, // 1
  22. 0b11011010, // 2
  23. 0b11110010, // 3
  24. 0b01100110, // 4
  25. 0b10110110, // 5
  26. 0b10111110, // 6
  27. 0b11100000, // 7
  28. 0b11111110, // 8
  29. 0b11110110, // 9
  30. 0b11101110, // A
  31. 0b00111110, // b
  32. 0b00011010, // C
  33. 0b01111010, // d
  34. 0b10011110, // E
  35. 0b10001110, // F
  36. 0b00000001 // .
  37. };
  38. //Pin connected to ST_CP of 74HC595
  39. int latchPin = 27;
  40. //Pin connected to SH_CP of 74HC595
  41. int clkPin = 13;
  42. //Pin connected to DS of 74HC595
  43. int dtPin = 14;
  44. // display value
  45. int dispVal = 1234;
  46. bool increment = true;
  47. char view[8];
  48. float test = 10.6;
  49. // timer and flag for example, not needed for encoders
  50. int dispDigit1 = 0;
  51. int dispDigit2 = 0;
  52. int dispDigit3 = 0;
  53. int dispDigit4 = 0;
  54.  
  55. void setup() {
  56.  
  57.  
  58. Serial.begin(115200);
  59. SerialBT.begin("FlottSB20"); //Bluetooth device name
  60. // Enable the weak pull down resistors
  61. pinMode(latchPin, OUTPUT); //ST_CP of 74HC595
  62. pinMode(clkPin, OUTPUT); //SH_CP of 74HC595
  63. pinMode(dtPin, OUTPUT); //DS of 74HC595
  64. //ESP32Encoder::useInternalWeakPullResistors=DOWN;
  65. // Enable the weak pull up resistors
  66. ESP32Encoder::useInternalWeakPullResistors = UP;
  67.  
  68. // use pin 19 and 18 for the first encoder
  69. encoder.attachHalfQuad(5, 23);
  70. // use pin 17 and 16 for the second encoder
  71.  
  72.  
  73. // set starting count value after attaching
  74. encoder.setCount(5000);
  75.  
  76. // clear the encoder's raw count and set the tracked count to zero
  77. encoder.clearCount();
  78. Serial.println("Encoder Start = " + String((int32_t)encoder.getCount()));
  79. // set the lastToggle
  80.  
  81. }
  82.  
  83. void loop() {
  84.  
  85. sprintf_P(view, "%+06.1f", mapfloat((int32_t)encoder.getCount(), 0, 5000.0, 0, 236.0));
  86. Serial.println( String((int32_t)encoder.getCount()));
  87. String temp = view;
  88. SerialBT.println(temp);
  89. temp.replace(".", "");
  90. Serial.println(temp);
  91. digitalWrite(latchPin, LOW);
  92.  
  93. shiftOut(dtPin, clkPin, LSBFIRST, digit_pattern[(int)temp.charAt(4) - '0']);
  94. shiftOut(dtPin, clkPin, LSBFIRST, digit_pattern[(int)temp.charAt(3) - '0'] | digit_pattern[16]);
  95. shiftOut(dtPin, clkPin, LSBFIRST, digit_pattern[(int)temp.charAt(2) - '0']);
  96. shiftOut(dtPin, clkPin, LSBFIRST, digit_pattern[(int)temp.charAt(1) - '0'] );
  97. digitalWrite(latchPin, HIGH);
  98.  
  99. delay(1000);
  100.  
  101. }
  102. float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) {
  103. return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment