Friday, November 29, 2024

Week 6: Flipping the Blinds

I was happy that I struggled so much with servos last week, because this week I knew going in that the servo wasn't going to go more than 180 degrees.  With that in mind, I started thinking about how to physically open and close the blinds using the servo.  I didn't use the photoresistor this time because (a) I'd already used it on past projects and felt comfortable with it, and (b) my kit actually didn't come with one, and I had only had access to one because of a kit I'd checked out from our library... which I'd already returned.

That said, I decided just to stick with the push button and focus on the servo and the physical aspects of getting the blinds to move.  My house has the blinds like these where you can twist the rod to tilt the blinds or pull the string to make them go up and down.  

I didn't think I could get the mechanics of the "up and down" part because for down you have to pull the cord off to the side and that seemed really complicated so I decided to go with the twisting part.  I tested it and found that the rod needed to rotate seven times in order to go from open to closed.  That was definitely going to be an issue with having a servo that could only go 180 degrees, but I thought maybe not insurmountable if I just used gear ratios.


Business as usual: Tinkercad

As per my standard operating procedure, I set up my model on Tinkercad, and got things working:


The code was relatively straightforward as well, since I already had programmed the button and had programmed a servo before.  But for some reason, I absolutely could not get the thing to work.  A seemingly-infinite amount of time later, I finally realized I was missing a reference.  I had this code:

servoBase.attach(A1);

and it should've been this code:

 servoBase.attach(servoPin);

So that was an hour of my life I wasn't getting back!  I now had working code and everything was going to be perfect.  I had it set up so that each time I pushed the button the servo either ran 180 degrees clockwise or 180 degrees counterclockwise (opening or closing the window).

#include <Servo.h>

Servo servoBase;
// We'll be controlling the servo from pin A1.
const int servoPin = 10;

int buttonPin = 2;
int buttonState = 0;
int goCW = 1;

void setup(){
 
  pinMode(buttonPin, INPUT);
 
  servoBase.attach(servoPin);
  servoBase.write(0);  

  Serial.begin(9600);

} // end setup()

void loop(){
 
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    Serial.println("Button Activated");  
    if (goCW == 1){    
      goCW = 0;
      servoCW();      
    } else {
      goCW = 1;
      servoCCW();
    } // end CW or CCW
  } //end if

} // end loop

void servoCW(){
  Serial.println("In Servo CW");  

  for(int i=0; i<=180; i=i+10)  {
   Serial.println(i);  
   servoBase.write(i);
   delay(200);
  }
 
} // end servoCW

void servoCCW(){
  Serial.println("In Servo CCW");  

  for(int i=180; i>=0; i=i-10)  {
   Serial.println(i);  
   servoBase.write(i);
   delay(200);
  }
 
} // end servoCCW

Next Problem: Nothing Uploads

Now being ready to upload the code to my breadboard I ran into a terrifying problem: the code would not upload to the breadboard.  Just wouldn't do it.  It compiled, everything was great, but then it just would not copy over to the Arduino.  

Clearly I'm just dumb and didn't connect things well.  Take out USB. Reconnect USB.  Try again.  No.

Clearly I just need to close the Arduino IDE and open it again.  Nope.

Clearly I need to the close the Arduino IDE, take out the USB, reconnect, the USB, then open the IDE again.  Keep trying, sweetie.

Okay clearly I need to do all that, plus restart my computer.  No dice.

Okay must just be this code.  Let's try uploading code from last week because we know that works.  But no, it doesn't!   Terror grips my soul.

Now we hit the forums.


I was able to confirm my Arduino board wasn't "fried" (thank all that is holy), but then resetting it still didn't actually help.  The next step on the forum was terrifying:

Okay so that was fun.


Good news is, it worked!  Now the code uploaded and I could breathe again. Everything's good from here on out, right?  Right?????

Pretend this isn't a problem: backwards button reading

For some reason, even though I hadn't changed anything else related to the button wiring in my code or on my breadboard, the button state was reading high even when it wasn't pressed (and reading low when it was pressed).  

I tried using ChatGPT, by giving it my code and asking what might be going on:


It gave me quite a few ideas for troubleshooting:



I attempted all the suggestions, including this one:

Change pinMode(buttonPin, INPUT); to pinMode(buttonPin, INPUT_PULLUP);

That still didn't work, so I changed the code to look for LOW instead of HIGH and just moved on.


Let's do this: The gear setup

It was time to pull out the Legos and some 3D printed gears I had lying around.  First, I made a little holder for the servo.


I got everything wired up and put together the servo system.  Success!


And because the Karma Gods are fickle, the screw that came with the box for the servo wasn't long enough to go through the gear and the servo.  Luckily I found a screw with the same diameter and just a little longer!


I put the gear on the servo, and then put together another two gears so we could get a better gear ratio (180 going to 270).  It wasn't great, but it looked like an okay-enough set up.


Now confident I could do this, I set out to start adding pairs of gears until I got my gear ratio to make the full 2520 degree (7 revolution) setup.




Things looked good - time to make it spin!


And... this is where the dream died.  I realized couldn't get the precision on the gears, and that even if I could, I wouldn't be able to get enough power on the servo to make all those rotations.

So all that work just to discover another way to not make a lightbulb...

I had one more trick up my sleeve.

Let's do this (again): The moment arm setup

My son's apartment has different kinds of blinds, that instead of a rotation just use a string pull to made the blades rotate.  I thought I might have a chance.


I got a paint stirring stick, drilled a hole in the middle to attach to the servo and drilled two larger holes on each end for the strings of the blinds.  If the servo could do the 180 degree rotation with each string on each side, it would fully open or close the blinds.


Now let's see how this turned out...



So essentially, the servo that came with the kit just wasn't strong enough to handle either set of blinds in my house.  I do feel like I have a "proof of concept" in that if I got a stronger servo, I might have been able to make this happen!  

(As I was lamenting my struggles, my father-in-law suggested a real-world application related to toilet paper dispensing, which gave me giggles and lifted my spirits!)


Saturday, November 23, 2024

Week 5: Choose your own adventure!

This one was fun!  I decided I wanted to use the random number generator to make a roulette wheel style spinner (with only a few numbers, not all of them!).  I thought I could use the servo motor, because apparently you can tell that exactly where to go.  My theory was to generate the random number in the code, then spin the servo a little bit for show, and then have it rotate to the right number on the board.  Since it already kind of had a "pointer," I figured it wouldn't be too bad.

I got the servo out, and realized it had to be assembled.  I felt like kind of a pro at this point, because I got to use a screwdriver and that felt Real (as the kids these days would say).


First of all, it took a while to pinpoint exactly which servo we had in the box, but I finally found the right one and found a wiring diagram: 


But no matter what I did, I couldn't get it to actually spin.  Didn't even get to the random number part, I just kept going back and forth trying to get it to spin.  (This was all on Tinkercad.)  I thought maybe the simulation software just wasn't great, so I tried wiring it up for real, but it still wasn't working.  A few more hours on Google, and I came across this gem:


Apparently they can't do a 360 degree spin at all and I was working with the wrong hardware to begin with!  So yeah, that was a fun afternoon...

Okay let's try something else.  There was also a motor in the kit, but that seemed a little scary.  Motors spin fast, and they have all kinds of extra things you have to put on the board to make it work.  I did see a motor project in the book though, and found the related code in the zip file, so I decided to give it a shot.  (If you're interested, read the comments in the code about how the extra parts work, it's kind of crazy how much extra stuff is going on at an electrical level that we can just wire up by pattern matching and move on.)

I decided to forego the idea of getting it to go to a specific number, and just wanted to get the motor to spin.  There were a lot of extra functions in the provided code, so I deleted all but the "spin the motor just normally" one, and used what we learned previous to wire it up to go on a button press.  But still in Tinkercad it wasn't working great.  Again, out of desperation, I decided to forego the model and just wire it up for real, expecting to be yet again disappointed.  But no!  It actually worked!  Success!!!!!


Now we're cookin' with gas!

The next step was to build something to hold the motor so it could spin.  Out came the Legos.  I also wanted to attach the number circle on the motor, so I needed a little base to glue onto the motor.


Now comes out the hot glue gun that I've used about four times in the last twenty years, and a misleadingly-short-and-easy amount of time later, my device was ready to go!


Everything was ready, I clicked the button.... and the stupid motor started spinning so fast both the paper and the wooden disc flew right off!  Okay, so now I have to figure out how to slow down the motor.

I had to go back to some of those functions I had previously deleted, because I remembered one of them said something about motor speeds.  Turns out you can control the motor, from 0 to 255, just like you'd kind of expect.  So all I really needed to do was maybe cut the motor speed by 75% and reassemble everything.

Of course the wooden disc was now 100% clogged with old glue, and I couldn't get the paper numbers off without ripping everything and potentially making the one wooden disc I had unusable.  So now I'm trying to rip out 25 year-old dried glue out of a tiny hole without ruining something glued to the other side of it.  After a toothpick and tiny Allen wrench failed, I found success using a tiny shrimp cocktail fork.  Getting everything reset took about an hour, but finally I was ready to try again.


I put everything together, set the motor really low, and.... Nothing Happened.  I knocked it down about 50%, thinking that would probably be enough, but still worried it was too high.  Not only was it not too high, it didn't even spin.  I could hear the motor trying to engage, but it didn't move.  Oh, no, I broke the motor!  Okay, maybe I didn't, but let's just try increasing the number a little bit.  

Turns out that the motor isn't spinning on a power of 0 to 255.  It's actually spinning on a power from <whatever gets it going> to 255.  And with the weight put on the motor, this guy wasn't going to start spinning until it had a power over at least 160.  I was really wary of it going too fast, though, so I didn't experiment too much - basically increased the power until I felt it was "just enough" to give it a decent spin.

With that success, I wanted to put in a bit of randomness, so I also put in a spin timer based on a random number, so the motor would spin anywhere from 1 to 4 seconds.  (I actually generated a number between 10 and 40 and multiplied by 100 instead of 1 to 4 and multiplying by 1000 so I'd get a little bit more variability.)


Here is the final version of the code.  Comments at the top came from the project documentation (I deleted a bunch of the comments and just left the ones in about the hardware).  I could definitely see real-life extensions, even with just board games, so this was really fun to put together.

/*
SPINNING A MOTOR

  Transistor:
 
    The transistor has three pins. Looking at the flat side with the
    pins down, the order is COLLECTOR, BASE, EMITTER.
   
    Connect the black wire on the motor to the
    COLLECTOR pin on the transistor.

    Connect the BASE pin through a 330 Ohm resistor to
    digital pin 9.
   
    Connect the EMITTER pin to GND.
 
  Motor:

    You've already connected the black wire on the motor to the
    COLLECTOR pin on the transistor.
   
    Connect the other (red) wire on the motor to 5V.
 
  Flyback diode:

    When the motor is spinning and suddenly turned off, the
    magnetic field inside it collapses, generating a voltage spike.
    This can damage the transistor. To prevent this, we use a
    "flyback diode", which diverts the voltage spike away from
    the transistor.

    Connect the side of the diode with the band (cathode) to 5V
    Connect the other side of the diode (anode) to the black wire
    on the motor.
*/

// We'll be controlling the motor from pin 9.
const int motorPin = 9;

int randomNumber;
int buttonPin = 2;
int buttonState = 0;

void setup(){
 
  // Set up the motor pin to be an output:
  pinMode(motorPin, OUTPUT);
  pinMode(buttonPin, INPUT);
 
  Serial.begin(9600);
  randomSeed(analogRead(0));

} // end setup()

void loop(){
 
  buttonState = digitalRead(buttonPin);
 
  if (buttonState == HIGH) {
     Serial.println("Button state is 1");  
      motorOnThenOff();      
  } //end if

} // end loop

void motorOnThenOff(){
  int onTime;  // milliseconds to turn the motor on
  int offTime; // milliseconds to turn the motor off
 
  randomNumber = random(10,41); // Generate a random # from 10 to 40
  Serial.println(randomNumber);  

  onTime = randomNumber*100;

  Serial.println("On");  
  analogWrite(motorPin, 185);   // turn the motor on (full speed)
  delay(onTime);                // delay for onTime milliseconds

  Serial.println("Off");        // Don't actually need this functionality
  analogWrite(motorPin, 0);     // - just leaving it in there in case I want it later
  delay(offTime);               //   and it doesn't hurt anything

} // end motorOnThenOff

Thursday, November 14, 2024

Week 4 Extension - Try a 7-Segment Display

Since I found a seven-segment display in the kit I checked out from the library, I figured I would give it a shot!  Step one of course was to get everything on Tinkercard, and once I just copied over from what I found on a few online resources, everything worked perfectly!

Ah, what a lovely day -- I'm going to get things done early....

Nope.

Wired everything the same as Tinkercad.  Pressed button.  Nothing.

Rewrote code so not dependent on the button.  Nothing.

Checked security of all the wires.  Nothing.

Pulled out all the wires and put them back together.  Still nothing.

Time for bed, defeated and ashamed.

The next day, clearly I must've just done it wrong.

Pulled out all the wires and put them back together.  Still nothing.  This is getting old.

I started looking online for all the ways to test the display itself -- clearly the part must be broken.  Unfortunately all the troubleshooting tips required using a multimeter, which I don't have.  But while looking at everything, I realized there are two types of 7-segment displays: Anode and Cathode.  I moved the one resistor wire from the + to the - side and .... magic!  Didn't get anything that looked like numbers on the display, but it at least started lighting up.

I did some more looking around online, and went back to Tinkercad.  This video I actually talk through it, so if you normally have sound off, having the sound on might help.


And here we get the circuit diagram!


All kinds of fun, but it's working now!


And here's the code!  Right now it's just doing the numbers 1 through six, but it could be edited to also do 0 and 7 - 9.

unsigned const int A = 13;
unsigned const int B = 12;
unsigned const int C = 11;
unsigned const int D = 10;
unsigned const int E = 9;
unsigned const int F = 8;
unsigned const int G = 7;
unsigned const int H = 6;
int randomNumber;
int buttonPin = 2;
int buttonState = 0;

void setup(){

  int index;
 
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(H, OUTPUT);

  pinMode(buttonPin, INPUT);
 
  Serial.begin(9600);
  randomSeed(analogRead(0));
 
  delay(100);
 
} // end setup


void loop(){
 
  int index;
 
  buttonState = digitalRead(buttonPin);
 
  if (buttonState == HIGH) {
     delay(100);
   
     randomNumber = random(1,7); // Generate a random # from 1 to 6
     Serial.println(randomNumber);
  }
  delay(500);
  //randomNumber = random(1,7);
   Serial.println(randomNumber);
 
  switch(randomNumber) {
    case 1:
      one();
      break;
    case 2:
      two();  
      break;
    case 3:
      three();
      break;
    case 4:
      four();
      break;
    case 5:
      five();
      break;
    case 6:
      six();
      break;
    default:
      Serial.println("Nothing happening");
      break;
  } // end switch
 
} // end main loop

void zero(void) {
  digitalWrite(A, HIGH);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
}

void one(void) {
   Serial.println("11111");
  digitalWrite(A, HIGH);
  digitalWrite(B, HIGH);
  digitalWrite(C, HIGH);
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
}

void two(void) {
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, HIGH);
  digitalWrite(H, HIGH);
}

void three(void) {
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
}

void four(void) {
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, HIGH);
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
}

void five(void) {
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, HIGH);
  digitalWrite(E, HIGH);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
}

void six(void) {
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, HIGH);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
}

void seven(void) {
  digitalWrite(A, HIGH);
  digitalWrite(B, HIGH);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
}

void eight(void) {
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
}

void nine(void) {
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
}



Week 4 Challenge - Roll a Die with a Button

This one went very, very smoothly on Tinkercad.  In real life, not so much.  There was soooooo much pain and suffering related to getting every dumb pin connected exactly right!

I also did not like that the center pin couldn't actually be in the center, since it needs its own input line.  The perfectionist in me was definitely not enjoying it. Also soooooo many wires!!!  The circuit diagram was a mess, and it was worse in real life!

In the video you can see that it's working, but also that it's a mess.


Per the video, I also did 100 trials and put the results in Excel to plot a histogram.  It's not a perfect uniform distribution, but since it's only 100 trials, I think the graph looked pretty good.


And now for the code!

// Arduino is like C so it indexes starting at 0
int ledPins[] = {3,4,5,6,7,8,9};
int randomNumber;
int buttonPin = 2;
int buttonState = 0;

void setup(){

  int index;

  for(index = 0; index < 7; index++){
    pinMode(ledPins[index],OUTPUT);
  }

  pinMode(buttonPin, INPUT);
 
  Serial.begin(9600);
  randomSeed(analogRead(0));
 
  // Turn all the LEDs off:
  for(index = 0; index < 7; index++)  {
    digitalWrite(ledPins[index], LOW);    
  }
  delay(100);
 
} // end setup


void loop(){
 
  int index;

   buttonState = digitalRead(buttonPin);
 
 
  if (buttonState == HIGH) {
    Serial.println("----------In the If Statement-------------------");
     // Turn all the LEDs off:
     for(index = 0; index < 7; index++)  {
       digitalWrite(ledPins[index], LOW);    
     }
     delay(100);
   
     randomNumber = random(1,7); // Generate a random # from 1 to 6
     Serial.println(randomNumber);
  }
 
  switch(randomNumber) {
    case 1:
      showOne();
      break;
    case 2:
      showTwo();  
      break;
    case 3:
      showThree();
      break;
    case 4:
      showFour();
      break;
    case 5:
      showFive();
      break;
    case 6:
      showSix();
      break;
    default:
      //Serial.println("Nothing happening");
      break;
  } // end switch
 
} // end main loop


void showOne()
{
  // Turn on #6, which is index 3
  digitalWrite(ledPins[3], HIGH);
} // end showOne()

void showTwo() {
  digitalWrite(ledPins[0], HIGH);
  digitalWrite(ledPins[6], HIGH);
} // end showTwo()

void showThree(){  
  digitalWrite(ledPins[1], HIGH);
  digitalWrite(ledPins[3], HIGH);
  digitalWrite(ledPins[5], HIGH);
} // end showThree()

void showFour(){
  digitalWrite(ledPins[0], HIGH);
  digitalWrite(ledPins[1], HIGH);
  digitalWrite(ledPins[5], HIGH);
  digitalWrite(ledPins[6], HIGH);
} // end showFour()

void showFive(){
  digitalWrite(ledPins[0], HIGH);
  digitalWrite(ledPins[1], HIGH);
  digitalWrite(ledPins[3], HIGH);
  digitalWrite(ledPins[5], HIGH);
  digitalWrite(ledPins[6], HIGH);
} // end showFive()

void showSix(){
  digitalWrite(ledPins[0], HIGH);
  digitalWrite(ledPins[1], HIGH);
  digitalWrite(ledPins[2], HIGH);
  digitalWrite(ledPins[4], HIGH);
  digitalWrite(ledPins[5], HIGH);
  digitalWrite(ledPins[6], HIGH);
} // end showSix()

Saturday, November 9, 2024

Photoresistor, Temperature Sensor, and Potentiometer!

I found out that our library had Arduino kits available for checkout and they had photoresistors in them!  It gave me just enough hope to work on putting together the same logic for the temperature sensor and then throwing in the previous work from the potentiometer.

Got it all working in Tinkercad, so that was Step 1.

Unfortunately, in the real world, I couldn't really do much with changing the temperature sensor - it didn't seem to respond to me touching it to try to make it warmer, but it did work in the Tinker model, and using the photoresistor and potentiometer worked just fine!



I didn't see any other sensors in the kit that I could mess with - I thought about maybe something that could sense sound - maybe that's the Piezo piece?  I'm not sure and I didn't have enough time to do more on it, so I just left it with what I had.  I really did enjoy getting all the colors to come out - I wish that my phone camera did a better job of capturing it.  This has made me realize the importance of having a good camera in the makerspace for the students to use!

And here's the code!

const int lightInputPin = 0;
const int tempInputPin = 1;
const int potInputPin = 2;

const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

// We'll also set up some global variables for the light level:
// I initially set them at 200 and 300, but will allow them to
//   change based on what happens in the system
int lightLevel, lightLow = 200, lightHigh = 300;

int tempLevel, tempLow = 200, tempHigh = 100;

int potLevel = 0;

void setup(){
 
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
  Serial.begin(9600);
}


void loop(){

  lightLoop();
  tempLoop();
  potLoop();

 
} // end main loop


void lightLoop(){
  int range = lightHigh - lightLow;

  lightLevel = analogRead(lightInputPin);
 
  if (lightLevel < lightLow) {
    lightLow = lightLevel;
  }
 
  if (lightLevel > lightHigh) {
    lightHigh = lightLevel;
  }

  // You don't need to cast as a float in tinkercad
  //   but when you move to Arduino IDE it's required
  lightLevel = (float) (lightLevel - lightLow) * 255 / range;
 
  analogWrite(BLUE_PIN, lightLevel);
} // end lightLoop


void tempLoop(){
   int range = tempHigh - tempLow;
 
  tempLevel = analogRead(tempInputPin);

  Serial.println("OG TempLevel");
  Serial.println(tempLevel);

  Serial.println("tempLow");
  Serial.println(tempLow);

  Serial.println("tempHigh");
  Serial.println(tempHigh);

  if (tempLevel < tempLow) {
    tempLow = tempLevel;
  }
 
  if (tempLevel > tempHigh) {
    tempHigh = tempLevel;
  }
 
  // You don't need to cast as a float in tinkercad
  //   but when you move to Arduino IDE it's required
  tempLevel = (float) (tempLevel - tempLow) * 255 / range;

  Serial.println("Adjusted TempLevel");
  Serial.println(tempLevel);

  analogWrite(GREEN_PIN, tempLevel);  
 
} // end temploop


void potLoop(){
  potLevel = analogRead(potInputPin);    
  potLevel = static_cast<int>((potLevel / 1024.0) * 255);
 
  analogWrite(RED_PIN, potLevel);
}

Nooooo, don't make me reflect on my learning!

 ... I just want to stick wires in breadboards and make froggies dance!!! Okay, but seriously, that stupid dancing frog was clearly my most ...