// declareer de PINOUT van de lampen buitenom de scope van Void Setup en de Void Loop
// opdracht 9 en 13 alleen dan voor 3 ledjes
int LampPin[] = {0, 1, 2,3};
int aanDelay = 25;
int uitDelay = 1000;
int lampDelay = 1000;
byte tempNum = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// Setup Pins
// Opdracht 1 alleen dan voor 3 lampjes
for (int idx = 0; idx <= 3; idx++){
pinMode(LampPin[idx],OUTPUT); // Lampjes initialiseren.
digitalWrite(LampPin[idx], LOW);
}
}
void loop() {
// put your main code here, to run repeatedly:
// Opdracht 2 alleen dan voor 3 lampjes
// Student nummer in code van lampjes
char studentNr[] = "1072654";
//studentNr.concat(1072654); // studentNr.length()
for (int idx = 0; idx <= 7; idx++){
tempNum = studentNr[idx];
Serial.println(studentNr);
Serial.println(tempNum);
INT2BIN(7,4);
delay(uitDelay);
for (int idx = 0; idx <= 3; idx++){
digitalWrite(LampPin[idx], LOW);
}
}
}
int INT2BIN(int nummer,int led){
char binary[4] = {0};
byte someValue = nummer; //For this example, lets convert the number 20
someValue += 16; //(led^2); //Voeg 16 (4^2 toe) zodat er altijd 4 getallen staan in de string
itoa(someValue,binary,2); //Conver someValue to a string using base 2 and save it in the array named binary
char* string = binary + 1; //get rid of the most significant digit as you only want 4 bits bij nul heb je anders nog 5 bits
// = binary + 1; //get rid of the most significant digit as you only want 4 bits bij nul heb je anders nog 5 bits
Serial.println(string);
Serial.println(binary);
for (byte idx = 0; idx <= (led-1); idx++){
//if (string[idx] = 1){
Serial.println(string);
digitalWrite(LampPin[idx], string[idx] -'0');
//}
//else{
//digitalWrite(LampPin[idx], LOW);
//}
delay(lampDelay);
}
return;
}