Arduino Starter Kit example Project 8 - Digital Hourglass

Arduino specifieke Software
Berichten: 5
Geregistreerd: 13 Jan 2016, 21:54

Arduino Starter Kit example Project 8 - Digital Hourglass

Berichtdoor Spiekes » 15 Jan 2016, 19:17

Beste,
we hebben in een les "Arduino Starter Kit example Project 8 - Digital Hourglass" (Arduino 1.6.5) getest met drie verschillende Arduino Uno's.
Als we het breadboard kantelen wanneer alle LED's branden begint de cyclus opnieuw op voorwaarde dat we dat relatief kort na het einde van een cyclus doen ; als we een kwartiertje of wat langer wachten gebeurd er niets : alle LED's blijven branden.
Heeft er iemand hier een verklaring voor?

Beste dank.

Advertisement

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

Re: Arduino Starter Kit example Project 8 - Digital Hourgl

Berichtdoor shooter » 16 Jan 2016, 09:30

er loopt teveel stroom, dus de voeding stopt ermee, weerstanden 150% maken helpt.
ofwel 330 ohm
paul deelen
shooter@home.nl

Berichten: 5
Geregistreerd: 13 Jan 2016, 21:54

Re: Arduino Starter Kit example Project 8 - Digital Hourgl

Berichtdoor Spiekes » 17 Jan 2016, 14:36

Zouden de LED's niet uitgaan zonder voeding?

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

Re: Arduino Starter Kit example Project 8 - Digital Hourgl

Berichtdoor shooter » 17 Jan 2016, 19:53

sorry verkeerde antwoord.
laat de software maar eens zien, wellicht doen jullie iets fout met een timer of zo,
paul deelen
shooter@home.nl

Berichten: 5
Geregistreerd: 13 Jan 2016, 21:54

Re: Arduino Starter Kit example Project 8 - Digital Hourgl

Berichtdoor Spiekes » 17 Jan 2016, 22:22

De code is gewoon "ge-upload" vanuit de integrated development environment van Arduino:
cpp code
/*
Arduino Starter Kit example
Project 8 - Digital Hourglass

This sketch is written to accompany Project 8 in the
Arduino Starter Kit

Parts required:
10 kilohm resistor
six 220 ohm resistors
six LEDs
tilt switch

Created 13 September 2012
by Scott Fitzgerald

http://www.arduino.cc/starterKit

This example code is part of the public domain
*/

// named constant for the switch pin
const int switchPin = 8;

unsigned long previousTime = 0; // store the last time an LED was updated
int switchState = 0; // the current switch state
int prevSwitchState = 0; // the previous switch state
int led = 2; // a variable to refer to the LEDs

// 600000 = 10 minutes in milliseconds
long interval = 600000; // interval at which to light the next LED

void setup() {
// set the LED pins as outputs
for (int x = 2; x < 8; x++) {
pinMode(x, OUTPUT);
}
// set the tilt switch pin as input
pinMode(switchPin, INPUT);
}

void loop() {
// store the time since the Arduino started running in a variable
unsigned long currentTime = millis();

// compare the current time to the previous time an LED turned on
// if it is greater than your interval, run the if statement
if (currentTime - previousTime > interval) {
// save the current time as the last time you changed an LED
previousTime = currentTime;
// Turn the LED on
digitalWrite(led, HIGH);
// increment the led variable
// in 10 minutes the next LED will light up
led++;

if (led == 7) {
// the hour is up
}
}

// read the switch value
switchState = digitalRead(switchPin);

// if the switch has changed
if (switchState != prevSwitchState) {
// turn all the LEDs low
for (int x = 2; x < 8; x++) {
digitalWrite(x, LOW);
}

// reset the LED variable to the first one
led = 2;

//reset the timer
previousTime = currentTime;
}
// set the previous switch state to the current state
prevSwitchState = switchState;
}

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

Re: Arduino Starter Kit example Project 8 - Digital Hourgl

Berichtdoor shooter » 17 Jan 2016, 23:10

na 6 keer is de led 7.
dan wordt digitalWrite(8,HIGH); maar dat is wel je switchpin, en dus gebeurt er niks meer.
als alle ledjes branden, dan moet je stoppen dus if (led >= 7) {led=2} is geen probleem want die staat toch al aan.
probeer maar eens door de switch op 11 te zetten.
en jullie hebben gelijk het is pas na 10 minuten = 600000 millis.
zet de tijd op 6000 dan gaat het allemaal wat sneller.
paul deelen
shooter@home.nl

Berichten: 5
Geregistreerd: 13 Jan 2016, 21:54

Re: Arduino Starter Kit example Project 8 - Digital Hourgl

Berichtdoor Spiekes » 21 Jan 2016, 01:05

I ben een absolute beginner in Arduino en ik heb " for (int x = 2; x < 8; x++) " nog niet geprobeerd maar denk toch dat die verklaring niet klopt :
1) ook als ik het interval verkort naar 10 seconden is het pas na meer dan 8 minuten dat de LED's niet uitgaan door het bord te bewegen
2) pin 2 tot en met 7 zijn OUTPUI , pin 8 is INPUT.

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

Re: Arduino Starter Kit example Project 8 - Digital Hourgl

Berichtdoor shooter » 21 Jan 2016, 10:40

pak een stukje papier en schrijf dan de cycli eens op.
de led gaat gewoon door want bij if led==7 staat niks, dus gaat gewoon door.
dat komt omdat {{{{{}}}}} niet kloppen.
en dus led kan 8 worden en dan staat er digitalWrite (8,HIGH) en dat is jouw input, en dat klopt natuurlijk niet.

wil je de code aub eerst even autoformat doen (Ctrl T) dan kopieren en hier tussen de code2=cpp zetten dat leest makkeleijker en ik hoef de ide niet te starten.
paul deelen
shooter@home.nl

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

Re: Arduino Starter Kit example Project 8 - Digital Hourgl

Berichtdoor nicoverduin » 21 Jan 2016, 13:39

shooter schreef:
wil je de code aub eerst even autoformat doen (Ctrl T) dan kopieren en hier tussen de code2=cpp zetten dat leest makkeleijker en ik hoef de ide niet te starten.

Je moest eens weten hoe vaak ik die code 2 erbij zit te zetten :mrgreen: Maar ik ben het helemaal met je eens met dat if statement
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 5
Geregistreerd: 13 Jan 2016, 21:54

Re: Arduino Starter Kit example Project 8 - Digital Hourgl

Berichtdoor Spiekes » 22 Jan 2016, 01:03

Beste,
ik heb uw suggestie geprobeerd en " if (led > 7) { led = 2 ; } " ingevoerd ; niet (led >= 7) : dan gaat laatste LED niet branden.
Dan gaat het prima.
Ik begrijp wel nog niet waarom het herstarten,door het board te bewegen na afloop van een cyclus, wel ging gedurende een relatief korte tijd na afloop en waarom het wat later niet meer ging.
Ik heb wel het interval op 1000 milliseconden gezet en ik heb uit het forum.arduino.cc ( Topic: Digital Hourglass will not execute at 600 000 ms (10mins) ) de code voor de seriële monitor overgenomen en in die monitor zie ik inderdaad dat zonder de aanpassing " if (led > 7) { led = 2 ; } " er telkens om de seconde een LED lijkt bij te komen; dit loopt door tot de teller op 54 staat en lijkt de teller op hol te slaan en loopt zeer snel tussen 46 en 54.
Wat U bedoelt met "tussen de code2=cpp zetten" begrijp ik niet maar dit is nu mijn code :

/*
Arduino Starter Kit example
Project 8 - Digital Hourglass

This sketch is written to accompany Project 8 in the
Arduino Starter Kit

Parts required:
10 kilohm resistor
six 220 ohm resistors
six LEDs
tilt switch

Created 13 September 2012
by Scott Fitzgerald

http://www.arduino.cc/starterKit

This example code is part of the public domain
*/

// named constant for the switch pin
const int switchPin = 8;

unsigned long previousTime = 0; // store the last time an LED was updated
int switchState = 0; // the current switch state
int prevSwitchState = 0; // the previous switch state
int led = 2; // a variable to refer to the LEDs

// 600000 = 10 minutes in milliseconds
long interval = 1000; // interval at which to light the next LED

void setup() {
Serial.begin(9600); // niet in handleiding
// set the LED pins as outputs
for (int x = 2; x < 8; x++) {
pinMode(x, OUTPUT);
}
// set the tilt switch pin as input
pinMode(switchPin, INPUT);
}

void loop() {
// store the time since the Arduino started running in a variable
unsigned long currentTime = millis();

// compare the current time to the previous time an LED turned on
// if it is greater than your interval, run the if statement
if (currentTime - previousTime > interval) {
// save the current time as the last time you changed an LED
previousTime = currentTime;
Serial.print ( "LED: "); // staat niet in handleiding
Serial.println (led); // staat niet in handleiding
// Turn the LED on
digitalWrite(led, HIGH);
// increment the led variable
// in 10 minutes the next LED will light up
led++;

if (led > 7) {
led = 2 ; // staat niet in de handleiding
// the hour is up
}
}

// read the switch value
switchState = digitalRead(switchPin);

// if the switch has changed
if (switchState != prevSwitchState) {
// turn all the LEDs low
for (int x = 2; x < 8; x++) {
digitalWrite(x, LOW);
}

// reset the LED variable to the first one
led = 2;

//reset the timer
previousTime = currentTime;
}
// set the previous switch state to the current state
prevSwitchState = switchState;
}


Misschien is het nuttig ook forum.arduino.cc hierover iets te laten weten.


Beste dank

Volgende

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Google Adsense [Bot], onejelatifumh en 85 gasten