Go Down

Topic: TM1637 with potentiometer, milliseconds (Read 1 time) previous topic - next topic

admin00

Jun 27, 2020, 08:29 am Last Edit: Jun 27, 2020, 08:36 am by admin00
Hello......
I've been programming lately, I want to ask if anyone can help me with this code? These are two codes I want to work as one. By turning the potentiometer, I want the milliseconds displayed on the display to affect the button. The button currently controls the relay and LED for 70 milliseconds.


#include <TM1637Display.h>
#define CLK 9
#define DIO 8
TM1637Display display(CLK, DIO);
int dly = 0;       // Set Delay time before next Upshift
int i = 0;         // Don't Touch!
int cutoff = 70 ;  // Set Engine Cutoff time (If you're using relay, do not set timing under 40ms)

void setup() {
 Serial.begin(9600);   // initialize serial communication at 9600 bits per second:
 display.setBrightness(3);
 pinMode(A0, INPUT);
 pinMode(2, INPUT_PULLUP);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 }
void loop(){
 unsigned int potVal = 0; // reset
 for (int i = 0; i < 64; i++) { // 64 analogue readings
 potVal += analogRead(A0); // add each value
 }
 potVal = map(potVal, 65472, 0, 41, 301); // pot wires reversed ?
 // potVal = map(potVal, 0, 65472, 0, 1000); // use this if connected 'normal'
 display.showNumberDec(potVal, true);
 
 int snsrstate=digitalRead(2);
 if (snsrstate==HIGH) {
 i=0;
 delay(50);
 }
 if (snsrstate==LOW && i==0) {
 i+=1;
 digitalWrite(5, LOW);
 digitalWrite(6, HIGH);
 delay(cutoff);
 digitalWrite(5, HIGH);
 digitalWrite(6, LOW);
 delay(dly);
 }
  }
 

admin00


Go Up