Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.3 kB
2
Indexable
Never
#include "SevenSegmentTM1637.h"

const byte PIN_CLK = 4;   // define CLK pin (any digital pin)
const byte PIN_DIO = 5;   // define DIO pin (any digital pin)
SevenSegmentTM1637    display(PIN_CLK, PIN_DIO);

char buffer[5];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  
  pinMode(13, OUTPUT);
  pinMode(19, INPUT);

  display.begin();            // initializes the display
  display.setBacklight(50);  // set the brightness to 100 %
  display.print("INIT");      // display INIT on the display
  delay(1000);                // wait 1000 ms
}

long adcVal;
int counter;
void loop() {
  // put your main code here, to run repeatedly:
  display.clear();  

  digitalWrite(13, HIGH);
  if (digitalRead(19) == 1) return;
  for(int i=0; i<32; i++) {
    adcVal += analogRead(4);
  }
  adcVal /= 32;

  counter++;
  Serial.print(counter);
  Serial.print(". ");
  display.clear();  
  adcVal = analogRead(4);
  float m = (5.2 - 0.0) / (0.0 - 1023.0);
  float b = 0 - m * 1023;
  float N = m * adcVal + b;

  double NN = (0.0000084812 * (pow(adcVal, 2))) - (0.0048*adcVal) + 0.3713;
  Serial.print(NN);
  Serial.print(" adcVal: ");
  sprintf(buffer, "%04d", int(N * 10));
  display.print(buffer); 
  Serial.println(adcVal);
  delay(500);
  digitalWrite(13, LOW);
}
Leave a Comment