Arduino Dice – A component (ongoing) exploration

The task demanded to connect more than two components to the Arduino processor in order to have a quick view the possibilities that this prototyping device can offer. In this experiment I used a tutorial that I searched in Instructables and I started to explore from there other potential uses: https://www.instructables.com/id/DIY-Arduino-LED-Dice/ For this experiment I used: -Arduino UNO processor -Bread Board -16 Jumper wires -1 220 ohm resistor   For the first step it is necessary to connect the button to the breadboard, we can place it in the middle. The energy will go from the 5V pin in the arduino processor to the positive lane of the breadboard, from there it must be connected through a cable to one of the sides of the button, the energy will continue through the 10k resistor and then arrive to the negative lane. From the negative lane we must connect the button to the pin 13 of the arduino processor. Every time we will click the button, the arduino processor will transmit a random number through the LEDS from 1 to 6:   In a second step we place the leds on the breadboard:     And then we connect all the negative ports together making “bridges” from one cathode to the other and we connect the positive¬† parts from the LED’s to the the pin ports 2,4,6,8,9,10, and 12 since the arduino processor will transmit the energy from there to the leds in every click:       Code:  
  • // Arduino LED Dice
  • // Made by Aleksandar Tsvetkov
  • // Using button debouncing logic from the Internet!
  • // Available on Instructables, just search it ūüôā
  • const¬†int¬†pins[6]¬†=¬†{2,¬†4,¬†6,¬†8,¬†10,¬†12};
  • int¬†buttonPin¬†=¬†13, buttonStatus, randNum, lastNum, i, lastDebounceTime, debounceDelay¬†=¬†150;
  • void¬†draw(int¬†randN);
  • void¬†setup()¬†{
  • ¬†¬†for¬†(i¬†=¬†0;¬†i¬†<=¬†5;¬†i++)¬†{
  • ¬† ¬† pinMode(pins[i], OUTPUT);
  • ¬†¬†}
  • ¬† pinMode(buttonPin, INPUT);
  • }
  • void¬†loop()¬†{
  • ¬† buttonStatus¬†=¬†digitalRead(buttonPin);
  • ¬†¬†if¬†(buttonStatus¬†==¬†HIGH¬†&&¬†(millis()¬†¬†lastDebounceTime)¬†>¬†debounceDelay)¬†{
  • ¬† ¬†¬†do¬†{
  • ¬† ¬† ¬† randNum¬†=¬†random(1,¬†6);
  • ¬† ¬†¬†}¬†while¬†(lastNum¬†==¬†randNum);
  • ¬† ¬† draw(randNum);
  • ¬† ¬† lastDebounceTime¬†=¬†millis();
  • ¬† ¬† lastNum¬†=¬†randNum;
  • ¬†¬†}
  • ¬† delay(100);
  • }
  • void¬†draw(int¬†randN)¬†{
  • ¬†¬†for¬†(i¬†=¬†0;¬†i¬†<=¬†5;¬†i++)¬†{
  • ¬† ¬† digitalWrite(pins[i], LOW);
  • ¬†¬†}
  • ¬†¬†for¬†(i¬†=¬†0;¬†i¬†<=¬†randN;¬†i++)¬†{
  • ¬† ¬† digitalWrite(pins[i], HIGH);
  • ¬†¬†}
  • }
    In a second step, I wanted tp use a Photoresistor instead of the button to create a “random” pattern of LED’s define by the light ambience that the photoresistor is receiving, so I replaced the button by a photoresistor in the breadboard and merged the code from a photoresistor exercise from Instructables web site, this second exploration was made with Mikhail Pikman:       The Instructables code: https://www.instructables.com/id/How-to-use-a-photoresistor-or-photocell-Arduino-Tu/  
// Arduino LED Dice
// Made by Aleksandar Tsvetkov
// Using button debouncing logic from the Internet!
// Available on Instructables, just search it ūüôā
const int pins[6] = {2, 4, 6, 8, 10, 12};
int pResistor = 13, buttonStatus, randNum, lastNum, i, lastDebounceTime, debounceDelay = 150;
int value;
void draw(int randN);
void setup() {
  for (i = 0; i <= 5; i++) {
    pinMode(pins[i], OUTPUT);
  }
   pinMode(pResistor, INPUT);// Set pResistor РA0 pin as an input (optional)
}
void loop() {
    value = analogRead(pResistor);
¬† //You can change value “25”
  if (value > 25){
    digitalWrite(pins[i], HIGH);  //Turn led off{
      randNum = random(1, 6);
    } else{
    digitalWrite(pins[i], LOW); //Turn led on;
The modified Code:
// Arduino LED Dice
// Made by Aleksandar Tsvetkov
// Using button debouncing logic from the Internet!
// Available on Instructables, just search it ūüôā
const int pins[6] = {2, 4, 6, 8, 10, 12};
int pResistor = 13, buttonStatus, randNum, lastNum, i, lastDebounceTime, debounceDelay = 150;
int value;
void draw(int randN);
void setup() {
  for (i = 0; i <= 5; i++) {
    pinMode(pins[i], OUTPUT);
  }
   pinMode(pResistor, INPUT);// Set pResistor РA0 pin as an input (optional)
   Serial.begin(9600);
}
void loop() {
    value = analogRead(pResistor);
¬† //You can change value “25”
  if (value < 30){
    digitalWrite(pins[i], HIGH);  //Turn led on{
      randNum = random(1, 6);
    } else{
    digitalWrite(pins[i], LOW); //Turn led on;
    draw(randNum);
    lastDebounceTime = millis();
    lastNum = randNum;
  }
  delay(100);
  Serial.println(value);
}
void draw(int randN) {
  for (i = 0; i <= 5; i++) {
    digitalWrite(pins[i], LOW);
  }
  for (i = 0; i <= randN; i++) {
    digitalWrite(pins[i], HIGH);
  }
}
The most interesting part of this exploration was to understand the large number of applications that simple input can create for creative and design purposes with the use and addition of codes.
<!– Auto Updating Copyright Script created with Rapid Purple Webmaster Tools (http://rapidpurple.com). –> <script language=”JavaScript”> <!– function y2k(number) { return (number < 1000) ? number + 1900 : number; } var today = new Date(); var year = y2k(today.getYear()); document.write(‘¬© ‘+year+’ Rapid Purple – All Rights Reserved’); //–> </script>
 

address: 20 Myasnitskaya ulitsa
(metro stations ‚ÄėLubyanka‚Äô and ‚ÄėKitay-Gorod‚Äô)
Moscow 101000 Russia

phone: +7(495)772-95-90 *15026

email: city@hse.ru