Stap 8: Het programma
Kopieer het volgende programma in de Arduino IDE:
/***************************************************** * Program name: Dice.ino * * Dice Pins: Green Red * 2 1 0 5 4 3 * 7 6 * 0 1 2 3 4 5 * * Button switch: PIn 8 ***************************************************** /***************************************************** * Setup code run at startup *****************************************************/ void setup() { randomSeed(analogRead(0)); for(int i=0; i<8; i++) pinMode(i, OUTPUT); pinMode(8, INPUT_PULLUP); } /***************************************************** * Loop runs in a continuous loop when setup finishes *****************************************************/ void loop() { int rnd; // Holds random number int i, j; // Indexes for for loops while(digitalRead(8) == HIGH); // Wait for button press. while(digitalRead(8) == LOW); // Wait for button release. randomSeed(millis()); // Blink at randon while dice roll. for(i=0; i<20; i++) { for(j=0; j<8; j++) { rnd=random(1, 3); if(rnd == 1) digitalWrite(j, HIGH); //Display random sequence } delay(100); for(j=0; j<8; j++) digitalWrite(j, LOW); //Clear random sequence } randomSeed(millis()); rnd=random(1,7); //First Die (green) switch(rnd) { case 1: digitalWrite(7, HIGH); break; case 2: digitalWrite(2, HIGH); break; case 3: digitalWrite(0, HIGH); digitalWrite(7, HIGH); break; case 4: digitalWrite(0, HIGH); digitalWrite(2, HIGH); break; case 5: digitalWrite(0, HIGH); digitalWrite(2, HIGH); digitalWrite(7, HIGH); break; case 6: digitalWrite(0, HIGH); digitalWrite(1, HIGH); digitalWrite(2, HIGH); break; } rnd=random(1,7); // Second Die (red) switch(rnd) { case 1: digitalWrite(6, HIGH); break; case 2: digitalWrite(5, HIGH); break; case 3: digitalWrite(3, HIGH); digitalWrite(6, HIGH); break; case 4: digitalWrite(3, HIGH); digitalWrite(5, HIGH); break; case 5: digitalWrite(3, HIGH); digitalWrite(5, HIGH); digitalWrite(6, HIGH); break; case 6: digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); break; } }
De volgende stappen laten zien hoe het programma uploaden naar de Attin84-chip.
Volg stap negen een Arduino gebruiken als een programmeur of stap tien als u van de USBtinyISP-programmeur gebruikmaakt.