TM1637 display code

algemene C code
Berichten: 7
Geregistreerd: 17 Mrt 2015, 21:54

TM1637 display code

Berichtdoor distroyer » 04 Okt 2017, 19:00

Geachte allemaal,

Ik loop even vast. Ik ben bezig met een counter functie, die heb ik gemaakt doormiddel van een switch case functie.
Nu wil ik daaraan een TM1637 4 digit display koppelen.

De teller wil ik dus weer geven op dat display. Op een of andere manier zie ik het even niet, en krijg het display niet aan de gang.

Wat doe ik verkeerd? Zowel in de diverse switch cases krijg ik hem niet aangeroepen, alsmede in het counter gedeelte zelf niet.

Code: Alles selecteren
#include <TM1637Display.h>

// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3


// this constant won't change:
const int  MicroSwitch1 = 9;    // the pin that the pushbutton is attached to
const int  MicroSwitch2 = 8;    // the pin that the pushbutton is attached to
const int CAMERA = 13;       // the pin that the Camera is attached to
const int RESET = 5;       // the pin that the Reset is attached to

// variables will change:
int buttonPushCounter = 0;   
int buttonState_MicroSwitch1 = 0;         
int lastButtonState_MicroSwitch1 = 0;

int buttonState_MicroSwitch2 = 0;

TM1637Display display(CLK, DIO);

int k;

void setup()
{
  // initialize the button pin as a input:
  pinMode(MicroSwitch1, INPUT);
  pinMode(MicroSwitch2, INPUT);
  // initialize the LED as an output:
  pinMode(CAMERA, OUTPUT);
  pinMode(RESET, OUTPUT);

  // initialize serial communication:
  Serial.begin(9600);
}

void loop()

  /*
  for(buttonPushCounter = 0; buttonPushCounter < 11; buttonPushCounter++)  //Interrate NumStep
   {
   display.showNumberDec(buttonPushCounter); //Display the Variable value;
   delay(500);  //A half second delay between steps.
   }
   */
  normal();
  counter();
}


void normal()
{
  // read the state of the pushbutton value:
  buttonState_MicroSwitch2 = digitalRead(MicroSwitch2);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState_MicroSwitch2 == HIGH) {     
    // turn LED on:   
    digitalWrite(CAMERA, HIGH);
    delay(200);
    digitalWrite(RESET, HIGH);   
  }
  else {
    // turn LED off:
    digitalWrite(CAMERA, LOW);
  }
}

void counter()
{
  // read the pushbutton input pin:
  buttonState_MicroSwitch1 = digitalRead(MicroSwitch1);

  // compare the buttonState to its previous state
  if (buttonState_MicroSwitch1 != lastButtonState_MicroSwitch1) {
    // if the state has changed, increment the counter
    if (buttonState_MicroSwitch1 == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      if(buttonPushCounter == 11){
        buttonPushCounter = 1;
      }
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
      display.showNumberDec(buttonPushCounter); //Display the Variable value;
      delay(500);  //A half second delay between steps.

    }
    else {
      // if the current state is LOW then the button
      // went from on to off:
      Serial.println("off");
    }
  }

  // save the current state as the last state,
  //for next time through the loop
  lastButtonState_MicroSwitch1 = buttonState_MicroSwitch1;
  switch(buttonPushCounter)
  {
  case 1:
    digitalWrite(CAMERA, LOW);
    Serial.println ("counter: 1");
    // On/Off test
    break;

  case 2:
    Serial.println ("counter: 2");
    display.showNumberDec(buttonPushCounter); //Display the Variable value;
    break;

  case 3:
    Serial.println ("counter: 3");
    display.showNumberDec(buttonPushCounter); //Display the Variable value;
    break;

  case 4:
    Serial.println ("counter: 4");
    display.showNumberDec(buttonPushCounter); //Display the Variable value;
    break;

  case 5:
    Serial.println ("counter: 5");
    display.showNumberDec(buttonPushCounter); //Display the Variable value;
    break;

  case 6:
    Serial.println ("counter: 6");
    display.showNumberDec(buttonPushCounter); //Display the Variable value;
    break;

  case 7:
    Serial.println ("counter: 7");
    display.showNumberDec(buttonPushCounter); //Display the Variable value;
    break;

  case 8:
    Serial.println ("counter: 8");
    display.showNumberDec(buttonPushCounter); //Display the Variable value;
    break;

  case 9:
    Serial.println ("counter: 9");
    display.showNumberDec(buttonPushCounter); //Display the Variable value;
    break;

  case 10:
    digitalWrite(CAMERA, HIGH);
    Serial.println ("counter: 10");
    display.showNumberDec(buttonPushCounter); //Display the Variable value;
    delay(200);
    digitalWrite(RESET, HIGH); 
    break;
  }
  Serial.println(buttonState_MicroSwitch1);

}




Advertisement

Berichten: 7
Geregistreerd: 17 Mrt 2015, 21:54

Re: TM1637 display code

Berichtdoor distroyer » 04 Okt 2017, 21:30

Laat maar, heb het al gevonden, was vergeten om de
Code: Alles selecteren
display.setBrightness(0x0a);  //set the diplay to maximum brightness
te gebruiken.

schijnbaar is die nodig om beeld te hebben.

Berichten: 4064
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: TM1637 display code

Berichtdoor shooter » 05 Okt 2017, 09:46

leuk he puzzelen (was maar 2,5 uur. dus prima gedaan.
paul deelen
shooter@home.nl

Berichten: 7
Geregistreerd: 17 Mrt 2015, 21:54

Re: TM1637 display code

Berichtdoor distroyer » 31 Okt 2017, 12:51

Ja opzich wel leuk puzzelen maar soms ook frustrerend ;)

Terug naar C code

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 7 gasten