Donation Dice

Donation Dice

We came up with a problem which is that people that need water, food, shelter and education and more, are struggling and don’t get those things that they need.

Our solution, the Donation Dice. The Donation Dice is a fun way of donating to life needs such as those who need water, shelter, food, education, transport and those who need money to survive in general. It is electronic dice that has numbers that correspond with different container. Whatever number you land on you must donate to that container.

To achieve this, you will need:

  • An Arduino kit
  • A computer
  • The Arduino Coding App
  • The Electronic Dice Code
  • 6 containers, labelled with D8-D13

Step 1

Step 1

 

  1. Code the Electronic Dice Code using the Arduino kit, a computer, the Arduino Coding App and the Electronic Dice Code.

 

/* This is the code to be completed

for the ThinkerShield Electronic Dice Project

Written by Thinkspace www.maas.museum/thinkspace

Ver 1.2

*/



// Declare variables.

int buttonPin = 7;

int buttonState = LOW;

int buzzerPin = 3;

int potPin = A5;

int scrollMaxDelay = 0;

int scrollDelay = 0;

int diceValue;

float seed = 0.0;



// Declare ledPins array.

int ledPins[] = {8, 9, 10, 11, 12, 13};



void setup()

{

// Set the seed to be random by reading

// in an unconnected pin.

seed = analogRead(0);

randomSeed(seed);



// Set all leds to OUTPUT by looping through the array.

for (int i=0; i<6; i++)

{

pinMode(ledPins[i], OUTPUT);

}



// Set the button to INPUT.

pinMode(buttonPin, INPUT);



// Set the pot to INPUT.

pinMode(potPin, INPUT);



// Set the buzzer to OUTPUT.

pinMode(buzzerPin, OUTPUT);



// Start the serial monitor.

Serial.begin(115200);

}



void loop()

{

// Read in the button and pot values.

buttonState = digitalRead(buttonPin);

scrollMaxDelay = map(analogRead(potPin), 100, 2000, 100, 1000);



// Check the button state.

if (buttonState == HIGH)

{



// Reset the scroll delay.

scrollDelay = 0;



// Jump to the dice roll function.

diceValue = roll();

// Now scroll the leds from the first LED to the LED

// which represents the randomly chosen number.

for(int i = 0; i < diceValue; i++)

{

Serial.println(i+1);

digitalWrite(ledPins[i], HIGH);

tone(buzzerPin, 100, 20);

delay(scrollDelay);

digitalWrite(ledPins[i], LOW);

scrollDelay += 10;

}



// Flash (and buzz) the chosen led 3 times then keep it on HIGH.

Serial.println(diceValue + 1);

Serial.println("------------");

for (int i=0; i<2; i++)

{

digitalWrite(ledPins[diceValue], HIGH);

tone(buzzerPin, 100, 500);

delay(500);

digitalWrite(ledPins[diceValue], LOW);

delay(500);

}



// Keep the final value on and reset the scrollDelay.

digitalWrite(ledPins[diceValue], HIGH);

tone(buzzerPin, 100, 500);

}

}



// Dice roll function.

int roll()

{

//Clear all leds.

for (int i=0; i<6; i++)

{

digitalWrite(ledPins[i], LOW);

}

//Scroll the leds up and down until

//ScrollMaxDelay is reached.

while (scrollDelay < scrollMaxDelay)

{

for (int i=0; i<6; i++)

{

Serial.println(i+1);

digitalWrite(ledPins[i], HIGH);

tone(buzzerPin, 100, 20);

delay(scrollDelay);

digitalWrite(ledPins[i], LOW);

scrollDelay +=20;

}

for (int i=4; i>0; i--)

{

Serial.println(i+1);

digitalWrite(ledPins[i], HIGH);

tone(buzzerPin, 100, 20);

delay(scrollDelay);

digitalWrite(ledPins[i], LOW);

scrollDelay +=20;

}

}

//Return a random integer between 0 and 6.

return random(0,6);

}

 

  1. Upload the code.
  2. Make sure all is good.
  3. It’s ready for use so grab the 6 containers, the Computer and get rolling

Add a comment