Schupp icon

7seg pressure esp32

Schupp | PRO | 01/06/22 10:57:31 AM UTC | 0 ⭐ | 300 👁️ | Never ⏰ | []
text |

3.06 KB

|

None

|

0 👍

/

0 👎

#include <ESP32Encoder.h>
#include "BluetoothSerial.h"
 #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
 BluetoothSerial SerialBT;
 ESP32Encoder encoder;
 // set the 7segment type (common Cathode or Anode)
const bool commonCathode = true; // I'm using common Cathode 7segment if you use common Anode then change the value into false.
// alpha-digit pattern for a 7-segment display
const byte digit_pattern[17] =
{
  // 74HC595 Outpin Connection with 7segment display.
  // Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7
  // a  b  c  d  e  f  g  DP
  0b11111100,  // 0
  0b01100000,  // 1
  0b11011010,  // 2
  0b11110010,  // 3
  0b01100110,  // 4
  0b10110110,  // 5
  0b10111110,  // 6
  0b11100000,  // 7
  0b11111110,  // 8
  0b11110110,  // 9
  0b11101110,  // A
  0b00111110,  // b
  0b00011010,  // C
  0b01111010,  // d
  0b10011110,  // E
  0b10001110,  // F
  0b00000001   // .
};
//Pin connected to ST_CP of 74HC595
int latchPin = 27;
//Pin connected to SH_CP of 74HC595
int clkPin = 13;
//Pin connected to DS of 74HC595
int dtPin = 14;
// display value
int dispVal = 1234;
bool increment = true;
char view[8];
float test = 10.6;
// timer and flag for example, not needed for encoders
int dispDigit1 = 0;
int dispDigit2 = 0;
int dispDigit3 = 0;
int dispDigit4 = 0;
 void setup() {
    Serial.begin(115200);
  SerialBT.begin("FlottSB20"); //Bluetooth device name
  // Enable the weak pull down resistors
  pinMode(latchPin, OUTPUT);    //ST_CP of 74HC595
  pinMode(clkPin, OUTPUT);      //SH_CP of 74HC595
  pinMode(dtPin, OUTPUT);       //DS of 74HC595
  //ESP32Encoder::useInternalWeakPullResistors=DOWN;
  // Enable the weak pull up resistors
  ESP32Encoder::useInternalWeakPullResistors = UP;
   // use pin 19 and 18 for the first encoder
  encoder.attachHalfQuad(5, 23);
  // use pin 17 and 16 for the second encoder
    // set starting count value after attaching
  encoder.setCount(5000);
   // clear the encoder's raw count and set the tracked count to zero
  encoder.clearCount();
  Serial.println("Encoder Start = " + String((int32_t)encoder.getCount()));
  // set the lastToggle
 }
 void loop() {
   sprintf_P(view, "%+06.1f", mapfloat((int32_t)encoder.getCount(), 0, 5000.0, 0, 236.0));
  Serial.println( String((int32_t)encoder.getCount()));
  String temp = view;
  SerialBT.println(temp);
  temp.replace(".", "");
  Serial.println(temp);
  digitalWrite(latchPin, LOW);
   shiftOut(dtPin, clkPin, LSBFIRST, digit_pattern[(int)temp.charAt(4) - '0']);
  shiftOut(dtPin, clkPin, LSBFIRST, digit_pattern[(int)temp.charAt(3) - '0'] | digit_pattern[16]);
  shiftOut(dtPin, clkPin, LSBFIRST, digit_pattern[(int)temp.charAt(2) - '0']);
  shiftOut(dtPin, clkPin, LSBFIRST, digit_pattern[(int)temp.charAt(1) - '0'] );
  digitalWrite(latchPin, HIGH);
   delay(1000);
 }
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Comments