timer naar 4digit display

algemene C code
Berichten: 86
Geregistreerd: 31 Dec 2015, 14:11

Re: timer naar 4digit display

Berichtdoor christiaan » 20 Jan 2016, 22:57

Klopt ook dat ze boven de uno zitten, hij zit nu op een mega aangesloten ivm de grote van mijn project. Oftewel code klopt alleen werkt ie niet.

Advertisement

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

Re: timer naar 4digit display

Berichtdoor shooter » 20 Jan 2016, 23:25

nee de code klopt gewoon niet. punt uit.
zowel voor de mega als de uno kloppen de pinnen niet.
dus waar is de code die je in de mega hebt zitten?
en waar is het schema.
paul deelen
shooter@home.nl

Berichten: 86
Geregistreerd: 31 Dec 2015, 14:11

Re: timer naar 4digit display

Berichtdoor christiaan » 20 Jan 2016, 23:28

De code die in mijn laatste bericht staat zit momenteel inde mega. Op de uno had ik ze op pin 3 en 4 zitten (din en clk) en nu dus verderop omdat ik die andere pinnen ergens anders voor gebruik

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: timer naar 4digit display

Berichtdoor nicoverduin » 20 Jan 2016, 23:37

Gelukkig het ligt niet aan de Mega.....
In jouw sketch moet je wel de pinnen goed definiëren. Want daar staat nu:
cpp code
const byte PIN_CLK = 39;   // define CLK pin (any digital pin)
const byte PIN_DIO = 38; // define DIO pin (any digital pin)
const byte d = 1000; // define D (delay) for 1000 milliseconds (= 1 second)
SevenSegmentExtended display(PIN_CLK, PIN_DIO);
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 86
Geregistreerd: 31 Dec 2015, 14:11

Re: timer naar 4digit display

Berichtdoor christiaan » 21 Jan 2016, 23:08

Heb er momenteel een andere code in zitten, en dat is onderstaande code. Deze code blijft erin, alleen hier werken de pinnen dus niet. Dit waarschijnlijk omdat de I2C pinnen onjuist zijn... Kan alleen dat probleem niet oplossen. Let op: Dit zijn weer 2 andere pinnen dan de 38 en 39, en nog steeds zit dit display aangesloten op een mega.

cpp code
/*
Basic usage example

Demonstrated some of the basic functionality of the library. Initialize the display, set the backlight brightness, print some text, count from 0 to 100 and print on display and blink some text.

Note: make sure to set your serial monitor to line end: NEW LINE!

The circuit:
* connect TM1637 pin CLK to Arduino pin D4
* connect TM1637 pin DIO to Arduino pin D5
* connect TM1637 pin Vcc to Arduino pin 5V
* connect TM1637 pin GND to Arduino pin GND

Created 25 September 2015
By Bram Harmsen

https://github.com/bremme/arduino-tm1637

*/

// include the SevenSegmentTM1637 library
#include "SevenSegmentTM1637.h"
#include "SevenSegmentExtended.h"

/* initialize global TM1637 Display object
* The constructor takes two arguments, the number of the clock pin and the digital output pin:
* SevenSegmentTM1637(byte pinCLK, byte pinDIO);
*/
const byte PIN_CLK = 43; // define CLK pin (any digital pin)
const byte PIN_DIO = 45; // define DIO pin (any digital pin)
const byte d = 1000; // define D (delay) for 1000 milliseconds (= 1 second)
SevenSegmentExtended display(PIN_CLK, PIN_DIO);

unsigned long Watch, _micro, time = micros();
unsigned int Clock = 0, R_clock;
boolean Reset = false, Stop = false, Paused = false;
volatile boolean timeFlag = false;
uint8_t h;
uint8_t m;
uint8_t s;


const int powerBtn = 2;
const int setBtn = 3;
bool startGame = false; // initialize gameEnd?


void setup() {
// put your setup code here, to run once:
pinMode(powerBtn, INPUT);
pinMode(setBtn, INPUT);

//Serial.begin(9600); // initializes the Serial connection @ 9600 baud
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
display.clear();

//Serial.begin(9600);
SetTimer(0,1,12); // 10 seconds
StartTimer();

}

void loop() {
// put your main code here, to run repeatedly:
int powerWaarde = digitalRead(powerBtn);
int setWaarde = digitalRead(setBtn);

CountDownTimer(); // run the timer

// this prevents the time from being constantly shown.
if (TimeHasChanged() )
{
//Serial.print(ShowHours());
//Serial.print(":");
// Serial.print(ShowMinutes());
// Serial.print(":");
// Serial.println(ShowSeconds());
ShowMinutes();
ShowSeconds();
display.printTime((uint8_t)m, s);
//Serial.print(":");
//Serial.print(ShowMilliSeconds());
//Serial.print(":");
//Serial.println(ShowMicroSeconds());
// This DOES NOT format the time to 0:0x when seconds is less than 10.
// if you need to format the time to standard format, use the sprintf() function.
}
}

boolean CountDownTimer()
{
static unsigned long duration = 1000000; // 1 second
timeFlag = false;

if (!Stop && !Paused) // if not Stopped or Paused, run timer
{
// check the time difference and see if 1 second has elapsed
if ((_micro = micros()) - time > duration )
{
Clock--;
timeFlag = true;

if (Clock == 0) { // check to see if the clock is 0
Stop = true; // If so, stop the timer
delay(100);
display.print("FAIL");
delay(10000);
}

// check to see if micros() has rolled over, if not,
// then increment "time" by duration
_micro < time ? time = _micro : time += duration;
}
}
return !Stop; // return the state of the timer
}

void ResetTimer()
{
SetTimer(R_clock);
Stop = false;
}

void StartTimer()
{
Watch = micros(); // get the initial microseconds at the start of the timer
Stop = false;
Paused = false;
}

void StopTimer()
{
Stop = true;
}

void StopTimerAt(unsigned int hours, unsigned int minutes, unsigned int seconds)
{
if (TimeCheck(hours, minutes, seconds) )
Stop = true;
}

void PauseTimer()
{
Paused = true;
}

void ResumeTimer() // You can resume the timer if you ever stop it.
{
Paused = false;
}

void SetTimer(unsigned int hours, unsigned int minutes, unsigned int seconds)
{
// This handles invalid time overflow ie 1(H), 0(M), 120(S) -> 1, 2, 0
unsigned int _S = (seconds / 60), _M = (minutes / 60);
if(_S) minutes += _S;
if(_M) hours += _M;

Clock = (hours * 3600) + (minutes * 60) + (seconds % 60);
R_clock = Clock;
Stop = false;
}

void SetTimer(unsigned int seconds)
{
// StartTimer(seconds / 3600, (seconds / 3600) / 60, seconds % 60);
Clock = seconds;
R_clock = Clock;
Stop = false;
}

int ShowHours()
{
return Clock / 3600;
}

int ShowMinutes()
{
//return (Clock / 60) % 60; // Original
m = (Clock / 60) % 60;
}

int ShowSeconds()
{
//return Clock % 60; // Original
s = Clock % 60;
}

unsigned long ShowMilliSeconds()
{
return (_micro - Watch)/ 1000.0;
}

unsigned long ShowMicroSeconds()
{
return _micro - Watch;
}

boolean TimeHasChanged()
{
return timeFlag;
}

// output true if timer equals requested time
boolean TimeCheck(unsigned int hours, unsigned int minutes, unsigned int seconds)
{
return (hours == ShowHours() && minutes == ShowMinutes() && seconds == ShowSeconds());
}

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

Re: timer naar 4digit display

Berichtdoor shooter » 22 Jan 2016, 12:50

is het nou zo moeilijk om
PIN_DIO=20
PIN_CLK=21
en dan uiteraard de draadjes ook in die pinnen insteken, dat is wel logisch denk ik.
paul deelen
shooter@home.nl

Gebruikers-avatar
Berichten: 636
Geregistreerd: 15 Nov 2015, 11:54

Re: timer naar 4digit display

Berichtdoor Gij Kieken » 22 Jan 2016, 14:36

Het display TM1637 moet je toch niet I²C aansturen, het is serieëel.
De voorbeeldtjes zitten bij de librarie.

Berichten: 86
Geregistreerd: 31 Dec 2015, 14:11

Re: timer naar 4digit display

Berichtdoor christiaan » 22 Jan 2016, 16:16

Dat is vrij lastig Shooter, omdat pinnen 20 en 21 gebruikt worden door mijn keypad. Vandaar de pinnen 43 en 45.
Maar op alle 4 de pinnen komt er geen leven in het display.

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

Re: timer naar 4digit display

Berichtdoor shooter » 22 Jan 2016, 19:41

heb even een voorbeeld opgehaald.

cpp code
/*
Basic usage example
Demonstrated some of the basic functionality of the library. Initialize the display, set the backlight brightness, print some text, count from 0 to 100 and print on display and blink some text.
Note: make sure to set your serial monitor to line end: NEW LINE!
The circuit:
* connect TM1637 pin CLK to Arduino pin 4 en ja die mag je wijzigen
* connect TM1637 pin DIO to Arduino pin 5 wel opletten dat het eerst clock en dan data is.
* connect TM1637 pin Vcc to Arduino pin 5V
* connect TM1637 pin GND to Arduino pin GND
Created 25 September 2015
By Bram Harmsen
https://github.com/bremme/arduino-tm1637
*/

// include the SevenSegmentTM1637 library
#include "SevenSegmentTM1637.h"

/* initialize global TM1637 Display object
* The constructor takes two arguments, the number of the clock pin and the digital output pin:
* SevenSegmentTM1637(byte pinCLK, byte pinDIO);
*/
const byte PIN_CLK = 43; // define CLK pin (any digital pin) hier dus
const byte PIN_DIO = 45; // define DIO pin (any digital pin)
SevenSegmentTM1637 display(PIN_CLK, PIN_DIO); init

// run setup code
void setup() {
Serial.begin(9600); // initializes the Serial connection @ 9600 baud
display.begin(); // initializes the display
display.setBacklight(100); // set the brightness to 100 %
display.print("INIT"); // display INIT on the display
delay(1000); // wait 1000 ms
};

// run loop (forever)
void loop() {
display.print("LOOP"); // display LOOP on the display
delay(1000); // wait 1000 ms
display.print("COUNTING SOME DIGITS");// print COUNTING SOME DIGITS
display.clear(); // clear the display
for (uint8_t i=100; i >0; i--) { // loop from 0 to 100
display.print(i); // display loop counter
delay(100); // wait 100 ms
}
display.clear(); // clear the display
display.print("SUCC"); // print SUCC for success
display.blink(); // blink SUCC
delay(1000); // wait 1000 ms
}



probeer deze eens?
even gezocht maar het is echt wel i2c, maar zit ook in de driver.
paul deelen
shooter@home.nl

Berichten: 86
Geregistreerd: 31 Dec 2015, 14:11

Re: timer naar 4digit display

Berichtdoor christiaan » 23 Jan 2016, 11:18

Geen resultaat Shooter...

VorigeVolgende

Terug naar C code

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 5 gasten