Sunday, November 28, 2021

Thanksgiving, Family, & Grad School, oh my!

 


As I sat down to work this week, I was hoping to knock my work out early and have the rest of the week for holidays with the family, but you know what they say about the best-laid plans.  It was not as easy to compartmentalize my life as my mind had imagined.

Setting up the Arduino circuit went fairly well.  I started with my dancing lights extension project from last week.  I needed to start with something I knew and felt comfortable with.  My first step was to get the breadboard set up like a die and the lights working on both sides of the breadboard.  Through research, I learned to connect the two sides together with jump wires - negative to negative and positive to positive. 




Since I was sort of starting from scratch on the design, I needed to draw out my plan.

Once I learned how to connect the two sides, I repositioned the LEDs into the shape of a die, then I ran the dancing lights code again to be sure the lights would work on both sides of the breadboard.  Tada!  It worked!

The next part of my project involved getting the lights to light up like a die.  Even after watching this week's videos, I am still struggling to understand the code.  Several of our classmates found a random led number project, but the LEDs were in a line, not the shape of a die.  I was able to copy the code and adjust it by changing the pin locations.  I do understand that much about the code.  When I first started running the code, I realized it wasn't lighting up like a die because I had didn't have the right HIGH and LOW for the die positions.  I was able to fix that on my own.  Yay!    The beginning of the code initializes the seven LED pins and the button. The next part of the code sets up the LEDs as OUTPUT and the button as INPUT.  The loop part of code sets is a random number generator and the different cases call the correct lights to turn on for each number in the spots on the die.  






And here is where the holidays and family got all mixed up with the grad school work.  I really wanted the lights to dance before they landed on the random number, but I could never figure out how to make that work.  I recorded the video you'll see below and THOUGHT I had posted it to the group for advice, but apparently, I did not. My daughter called and needed some mom time and my son, who lives is in Lubbock, flew in for the holiday, and Thanksgiving dinner needed preparing.  My bonus daughter wasn't able to spend Thanksgiving with us so we had a family outing at Top Golf.  Once the family time took over, I kind of forgot about school 🤷‍♀️.  Once I figured out I had missed an assignment, I began to wonder how I managed the holidays and grad school last year - but guess what?  I didn't!  I started grad school in the spring.  This is all new, but I'm figuring it out.  So, here's the video I thought I posted.  It is showing the code works to generate random numbers at the click of the button in the different shapes of a die.  If anyone would like to share how to add the dancing light code with the code I have, I would love to know how to make it happen.  


Here is the graph of the numbers generated from one hundred rolls.


I think students would really enjoy this project.  It would be fun if you had enough lights to randomly generate letters or words.

I hope you all had a wonderful Thanksgiving!  Happy tinkering this week!

It's been a long time since we have all been together! 
This mama's heart is happy.


Saturday, November 20, 2021

Failing Forward with Arduino Coding

In this week's Arduino challenge, we were asked to tackle Practice Circuits #3 and #4.  Circuit #3 involved programming the RGB light which is an LED light that can make multiple colors when coded correctly.  I had always wondered how Christmas lights could be multiple colors in one bulb; at least now I have some idea.  When I showed my husband the RGB circuit and colorful light, he asked two questions:   1) What class are you taking that you have to do that? 2)  When are you going to program our Christmas lights?  (Ha-ha - I think I need a little more practice). Circuit #4 was dancing LEDs.  This was fun, once I figured out how to make get everything set up and the code running correctly.  Although I am not ready to tackle coding our Christmas light display to music, I am gaining a better understanding of how it could be done.

RGB LED

In the RGB coding the clear LED will light up multiple colors based on the coding of high or low for the blue, red, and green pins.  It's all about combing the colors to get the desired color.  On my first attempt, the code was correct as I could tell by the blinking light on the Arduino, but my RGB wasn't working.


When I realized that the code was running, but my light wasn't changing colors, I started over and reset everything back up.  I believe I had the center wire in the wrong place, but I didn't take a before and after picture.  I did, however, take a video of the working program.




Here are some pictures of the board and the working code:

const int RED_PIN = 9;

const int GREEN_PIN = 10;

const int BLUE_PIN = 11;


int DISPLAY_TIME = 100;  


void setup() {

 

  pinMode(RED_PIN, OUTPUT);

  pinMode(GREEN_PIN, OUTPUT);

  pinMode(BLUE_PIN, OUTPUT); }


void loop() {

  

  mainColors();


showSpectrum(); }


void mainColors() {


  digitalWrite(RED_PIN, LOW);

  digitalWrite(GREEN_PIN, LOW);

  digitalWrite(BLUE_PIN, LOW);


  delay(1000);


  digitalWrite(RED_PIN, HIGH);

  digitalWrite(GREEN_PIN, LOW);

  digitalWrite(BLUE_PIN, LOW);


  delay(1000);


  digitalWrite(RED_PIN, LOW);

  


digitalWrite(GREEN_PIN, HIGH);

  digitalWrite(BLUE_PIN, LOW);


  delay(1000);


  digitalWrite(RED_PIN, LOW);

  digitalWrite(GREEN_PIN, LOW);

  digitalWrite(BLUE_PIN, HIGH);


   delay(1000);


  digitalWrite(RED_PIN, HIGH);

  digitalWrite(GREEN_PIN, HIGH);

  digitalWrite(BLUE_PIN, LOW);


  delay(1000);


  digitalWrite(RED_PIN, LOW);

  digitalWrite(GREEN_PIN, HIGH);

  digitalWrite(BLUE_PIN, HIGH);


  delay(1000);


  digitalWrite(RED_PIN, HIGH);

  digitalWrite(GREEN_PIN, LOW);

  digitalWrite(BLUE_PIN, HIGH);


  delay(1000);


  digitalWrite(RED_PIN, HIGH);

  digitalWrite(GREEN_PIN, HIGH);

  digitalWrite(BLUE_PIN, HIGH);


  delay(1000); }


void showSpectrum() {

  int x;  // define an integer variable called "x"


  for (x = 0; x < 768; x++)  {

    showRGB(x);  // Call RGBspectrum() with our new x

    delay(10);   // Delay for 10 ms (1/100th of a second)  } }


void showRGB(int color) {

  int redIntensity;

  int greenIntensity;

  int blueIntensity;


  if (color <= 255)  {

    redIntensity = 255 - color;   

    greenIntensity = color;        

    blueIntensity = 0;  }

  else if (color <= 511) {

    redIntensity = 0;                     

    greenIntensity = 255 - (color - 256); 

    blueIntensity = (color - 256); }

else // color >= 512 {

    redIntensity = (color - 512);         

    greenIntensity = 0;                   

    blueIntensity = 255 - (color - 512); }

  

  analogWrite(RED_PIN, redIntensity);

  analogWrite(BLUE_PIN, blueIntensity);

  analogWrite(GREEN_PIN, greenIntensity); }


Dancing Lights


Our second programmed circuit for the week was to program a row of lights to blink in different combinations.  To make this variety happen there was a lot of coding, that involved the speed of the lights and where the blinking started and finished.  Below is a video of dancing Arduino lights.  If only I could make my Christmas lights do this to music.  I can't even imagine the amount of programming that takes.  


In this coding sequence, the lights are numbered according to their pin location.  This is what programs the lights when to be on or off. Each LED needs a jumper wire and a resistor.  The jumper wires connect to the digital pins.  Mine does not look as pretty as the drawing, but it worked on the first try.  YAY!




I am proud of myself for getting the circuits built and coding them to work.  I am slowly beginning to understand how things work, but I still have a lot to learn.  The learning curve is huge, but I am building a lot of dendrites as  I tackle each week's challenge.

Code for Dancing Lights.

int ledPins[] = {2,3,4,5,6,7,8,9};


void setup() {

  int index;

  for(index = 0; index <= 7; index++); {

    pinMode(ledPins[index],OUTPUT) }

} void loop()

{

//oneAfterAnotherNoLoop();  // Light up all the LEDs in turn  //oneAfterAnotherLoop();  // Same as oneAfterAnotherNoLoop,

                      // but with much less typing

   //oneOnAtATime();         // Turn on one LED at a time,

                             // scrolling down the lin

  //pingPong();             // Light the LEDs middle to the edges

  marquee();              // Chase lights like you see on signs

//randomLED();            // Blink LEDs randomly

} void oneAfterAnotherNoLoop() {

  int delayTime = 100; // time (milliseconds) to pause between LEDs

                       // make this smaller for faster switching

 // turn all the LEDs on:


  digitalWrite(ledPins[0], HIGH);  //Turns on LED #0 (pin 2)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[1], HIGH);  //Turns on LED #1 (pin 3)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[2], HIGH);  //Turns on LED #2 (pin 4)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[3], HIGH);  //Turns on LED #3 (pin 5)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[4], HIGH);  //Turns on LED #4 (pin 6)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[5], HIGH);  //Turns on LED #5 (pin 7)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[6], HIGH);  //Turns on LED #6 (pin 8)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[7], HIGH);  //Turns on LED #7 (pin 9)

  delay(delayTime);                //wait delayTime milliseconds  

 

  // turn all the LEDs off:

  

  digitalWrite(ledPins[7], LOW);   //Turn off LED #7 (pin 9)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[6], LOW);   //Turn off LED #6 (pin 8)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[5], LOW);   //Turn off LED #5 (pin 7)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[4], LOW);   //Turn off LED #4 (pin 6)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[3], LOW);   //Turn off LED #3 (pin 5)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[2], LOW);   //Turn off LED #2 (pin 4)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[1], LOW);   //Turn off LED #1 (pin 3)

  delay(delayTime);                //wait delayTime milliseconds

  digitalWrite(ledPins[0], LOW);   //Turn off LED #0 (pin 2)

  delay(delayTime);                //wait delayTime milliseconds  

}

void oneAfterAnotherLoop()

{

  int index;

  int delayTime = 100; // milliseconds to pause between LEDs

                       // make this smaller for faster switching

  for(index = 0; index <= 7; index++)

{

    digitalWrite(ledPins[index], HIGH);

    delay(delayTime);                }                                  

  for(index = 7; index >= 0; index--)

 {

    digitalWrite(ledPins[index], LOW);

    delay(delayTime);

  }               

}

void oneOnAtATime()

{

  int index;

  int delayTime = 100; // milliseconds to pause between LEDs

                       // make this smaller for faster switching

   // step through the LEDs, from 0 to 7

  for(index = 0; index <= 7; index++)

  {

    digitalWrite(ledPins[index], HIGH);  // turn LED on

    delay(delayTime);                    // pause to slow down

    digitalWrite(ledPins[index], LOW);   // turn LED off

  }

}

void pingPong()

{

  int index;

  int delayTime = 100; // milliseconds to pause between LEDs

                       // make this smaller for faster switching

  // step through the LEDs, from 0 to 7


  for(index = 0; index <= 7; index++)

  {

    digitalWrite(ledPins[index], HIGH);  // turn LED on

    delay(delayTime);                    // pause to slow down

    digitalWrite(ledPins[index], LOW);   // turn LED off

  }


  // step through the LEDs, from 7 to 0

  

  for(index = 7; index >= 0; index--)

  {

    digitalWrite(ledPins[index], HIGH);  // turn LED on

    delay(delayTime);                    // pause to slow down

    digitalWrite(ledPins[index], LOW);   // turn LED off

  }

}

void marquee()

{

  int index;

  int delayTime = 200; // milliseconds to pause between LEDs

                       // Make this smaller for faster switching

  // Step through the first four LEDs

  // (We'll light up one in the lower 4 and one in the upper 4)

  for(index = 0; index <= 3; index++) // Step from 0 to 3

  {

    digitalWrite(ledPins[index], HIGH);    // Turn a LED on

    digitalWrite(ledPins[index+4], HIGH);  // Skip four, and turn that LED on

    delay(delayTime);                      // Pause to slow down the sequence

    digitalWrite(ledPins[index], LOW);     // Turn the LED off

    digitalWrite(ledPins[index+4], LOW);   // Skip four, and turn that LED off

  }

}

void randomLED()

{

  int index;

  int delayTime;

  index = random(8); // pick a random number between 0 and 7

  delayTime = 100;

  digitalWrite(ledPins[index], HIGH);  // turn LED on

  delay(delayTime);                    // pause to slow down

  digitalWrite(ledPins[index], LOW);   // turn LED off

}


Week 3 Challenge - Combining what we've learned


For this challenge, I chose to combine the blinking LED lights with the pentiometer.  I had success and would like to play with it more by additional code for the light pattern.  



For this challenge, I understand how the blinking lights work and how the potentiometer controls the speed.  I wanted to also use the RGB, but I couldn't figure out how to get that to work.  I thought I understood the RGB.  The longest lead in the RGB needs to be connected to the ground.  I couldn't think how to set it up and code it.  Perhaps I will try again next week on or solo build.  

As I reflect on my learning this week, I am reminded of students who do well enough to get by in class, but yet might not have a thorough understanding.  I am slowly understanding more, yet there are still things I am confused about.  I am able to complete my assignments, but I don't always feel confident that what I have done is correct.  As an adult, I am pushing through and acknowledging what I know and what I need help with, but do our students do this, or do they just accept defeat and give up on the possibility of understanding fully.

Points to ponder for sure.

Below is my code for the combined circuit challenge.

int ledNum = 6;

int ledPin[] = {4, 5, 6, 7, 8, 9};

int delayTime = 500;

int potPin = A0;


void setup() 

{

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

    pinMode (ledPin[i], OUTPUT);

  }

}

void loop() {

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

    delayTime = analogRead(potPin);

    digitalWrite(ledPin[i], HIGH);

    delay(delayTime);

    digitalWrite(ledPin[i], LOW);

  }

  for (int i = 5; i > 1; i--) {

    delayTime = analogRead(potPin);

    digitalWrite(ledPin[i], HIGH);

    delay(delayTime);

    digitalWrite(ledPin[i], LOW);

}

}

Sunday, November 14, 2021

Arduino Success - Feeling Accomplished

 Last week, my "making" left me feeling like a hot mess, but after a reboot, some tutorials, and a little time at home, I was able to complete the blinking LED light challenge.


I was even able to have success at adjusting the code and getting the light to blink at a different speed.




After my success, I was excited, but a little apprehensive about Challenge #2.  For this challenge, we were asked to use a potentiometer on the Arduino to adjust the dimness and speed of the blinking LED.  A potentiometer is like a volume control on your TV or cell phone.  The frequency is adjusted when you turn it.  To my surprise, I was successful on my first attempt - yay me!




I'm honestly not sure I completely understand how the entire circuit works, but I do understand that there are three wires connecting the potentiometer so that it is possible to have the adjustment with the turning of the knob.  The center wire connects the potentiometer to the analog in which allows it to have more frequency.  The resister is connected to the digital side.  The ground connection completes the circuit.  I am still learning the vocabulary and understanding the ins and outs of circuits and the programming.  I did do some extensions which are below.


Because I was catching up from last week, I feel like I still have quite a bit of learning to do as far as the coding and exactly how the circuits work.  I am way out of my comfort zone, but am enjoying the challenge.  I am hoping to have more time to tinker and explore this week. For this challenge, I started by looking closely at the schematic in my book and following it exactly.  When I got to the coding, it seemed a little bit overwhelming and I wasn't sure what to take out, or what everything meant so I turned to our discussion board to read what others had done. Thank goodness for collaboration when we aren't sure what we are doing.  I am reminded that we can still learn by seeing what others have done.  It gives us something to start with and can begin to make our own connections with more practice.  

As I was playing with this challenge, I couldn't help but think of Christmas lights.  We are the Christmas house on our block with all of our lights and decorations.  We have some strands of lights where we can push a button and change the type of blinking from twinkling to flashing or dimming in and out.  This would be an example of a potentiometer changing the frequency and action of the circuit.  I can't imagine the programming that must go in to the homes that have their Christmas lights programmed to music, but now I am definitely more curious.

Here's to more learning this week as we tinker and grow as learners!