Beste,
Ik wil een programmaatje maken die in 7 op de 10 keren een led laat oplichtten en in 3 op de 10 keren niet,ik heb dit geprobeerd met het volgende programma;
/*
set pin numbers:
*/
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 15; // the number of the LED pin
long randNumber;
const int output = 8;
int led = 13;
const int randompin = 0;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
pinMode(led, OUTPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
randNumber = random(10);
Serial.println (randNumber);
}
else {
// turn LED off:
analogWrite(randompin, LOW);
}
delay(50);
if (randNumber <= 7) {
digitalWrite (output, HIGH);
delay(1000);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
else {
digitalWrite (output, LOW);
}
}
Maar dit werkt niet,de led blijft altijd branden. Zijn er nog andere opties om zo'n sequentie te programmeren?
Alvast bedankt
Mvg Lowie
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.