1_9 RGB Color Mixer

Red-Green-Blue LED Color Mixer

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


/* Power multiple legs of the multicolor (RGB) LED light on and off to create blended colors */ void setup(){ pinMode(9,OUTPUT); //set the multicolor LED to OUTPUT pinMode(10,OUTPUT); pinMode(11,OUTPUT); } void loop(){ digitalWrite(9,HIGH); //turn on the LED color connected to pin 9 delay(1000); //Wait 1000 milliseconds (1 second) with only one color on. digitalWrite(10,HIGH); //turn on a second color using pin 10 delay(1000); //Wait 1000 milliseconds digitalWrite(11,HIGH); //turn on a third color using pin 11 delay(1000); //Wait 1000 milliseconds digitalWrite(9,LOW); //turn off the first color on pin 9 delay(1000); //Wait 1000 milliseconds digitalWrite(10,LOW); //turn off the second color on pin 10 delay(1000); //Wait 1000 milliseconds digitalWrite(11,LOW); //turn off the third color on pin 11 delay(1000); //Wait 1000 milliseconds before starting the loop over } // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

1_8 analogWrite Motor Strength

analogWrite Motor Buzz Strength

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


// Set the strength of the motor's buzz to three different levels void setup(){ pinMode(3,OUTPUT);//Set pin 3 to receive power } void loop(){ analogWrite(3,80); //Set motor strength to 80. It can range from 0-255 delay(1000); //Wait 1000 milliseconds (1 second) at strength 80 analogWrite(3,160); //Set strength to 160, double the last function delay(1000); //Wait 1000 milliseconds analogWrite(3,240); //Set strength almost to maximum delay(1000); //Wait 1000 milliseconds before restarting the loop } // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenge? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

1_7 analogWrite Brightness

analogWrite the Brightness of an LED

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


/* Change the brightness of an LED to three different levels Only LED colors 9, 10, and 11 can use the analogWrite() function used here. */ void setup(){ pinMode(9,OUTPUT); //Set LED 9 to receive power } void loop(){ analogWrite(9,80); //Set brightness to 80. Brightness can range from 0-255 delay(1000); //Wait 1000 milliseconds (1 second) at brightness 80 analogWrite(9,80); //Set brightness to 160, double the last function. delay(1000); //Wait 1000 milliseconds analogWrite(9,80); //Set brightness almost to maximum delay(1000); //Wait 1000 milliseconds before restarting the loop } // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenge? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

1_6_1 Alternate LED Blinks Bug

Bug Hunt! Test your Troubleshooting.

Prefer listening over reading? Click the play button in the audio bar.

Here’s how Bug Hunts work:

We’ve taken the example code from the last project and inserted errors into it. These errors might be spelling problems, syntax, or we might have changed up how the program works altogether!

The goal of the Bug Hunt is to find and fix the errors so that when you upload the code, it runs just like the example code did on the project page.

Try these steps in order to solve a Bug Hunt:

1) Look over the code closely first, looking for anything that is out of place. We recommend you do this first to build up your ‘bug hunting instincts’.

2) Press ‘Upload the Code’ with your board plugged in and the circuit built. The code won’t work, but it will show you the errors that the computer found - these will pop up in a box just below the code editor. These clues are sometimes vague or confusing, but they may help you find out where the problem is.

3) Check your code references, especially for the functions that have turned red when you hit “Upload”. Compare the syntax of your reference book to the syntax in your code editor here.

After you’ve fixed the bug and the code is working again, hit ‘Restore’ so you can see the code how it was before you fixed it. Is the bug obvious to you now? Reviewing like this will make it easier to find bugs in future programs!

Get stuck? Click on ‘Need a Hint?’ below. It will provide a clue about what’s wrong in this program.

/* Buggy: Blink two LEDs back and forth */ void setup(){ pinMode(8,OUTPUT); //Set LED 8 to receive power pinMode(12,OUTPUT); //Set LED 12 to receive power } void loop(){ digitalWrite(8,high);// turn on pin 8 digitalWrite(12,LOW);//turn off pin 12 delay(1000);//delay 1000 milliseconds (1 second) digitalWrite(8,low);//turn off pin 8 digitalWrite(12,HIGH);//turn on pin 12 delay(1000);//wait 1000 millisecond before restarting the loop } // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Check the capitalization of the words. Most code follows very strict rules about which words or letters are capitalized, and the computer won't recognize a command that isn't capitalized correctly!

Most commonly used keywords in code get highlighted to a new color when they are entered correctly. You can scan over the code with your eyes to see if anything sticks out that isn't highlighted.

1_6 Alternate LED Blinks

Alternate LED Blinks

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


/* Blink two LEDs back and forth */ void setup(){ pinMode(8,OUTPUT); //Set LED 8 to receive power pinMode(12,OUTPUT); //Set LED 12 to receive power } void loop(){ digitalWrite(8,HIGH);// turn on port 2 digitalWrite(12,LOW);//turn off port 6 delay(1000);//delay 1000 milliseconds (1 second) digitalWrite(8,LOW);//turn off port 2 digitalWrite(12,HIGH);//turn on port 6 delay(1000);//wait 1000 millisecond before restarting the loop } // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

1_5 Serial Print a Message

Serial Print a Message

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


/* Display a message on the serial monitor when the loop ends*/ void setup(){ Serial.begin(9600); //Start serial monitor with speed 9600. Don't change the 9600 } void loop(){ delay(1000); //Wait 1000 milliseconds (1 second) with the code 'paused' Serial.println("Loop Ends!"); //print the message 'loop ends' on a new line each time } //Don't forget to open the monitor by clicking 'Monitor' after uploading this code! // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

1_4_1 Play 3 Tones Bug Hunt

Bug Hunt! Test your Troubleshooting.

Prefer listening over reading? Click the play button in the audio bar.

Here’s how Bug Hunts work:

We’ve taken the example code from the last project and inserted errors into it. These errors might be spelling problems, syntax, or we might have changed up how the program works altogether!

The goal of the Bug Hunt is to find and fix the errors so that when you upload the code, it runs just like the example code did on the project page.

Try these steps in order to solve a Bug Hunt:

1) Look over the code closely first, looking for anything that is out of place. We recommend you do this first to build up your ‘bug hunting instincts’.

2) Press ‘Upload the Code’ with your board plugged in and the circuit built. The code won’t work, but it will show you the errors that the computer found - these will pop up in a box just below the code editor. These clues are sometimes vague or confusing, but they may help you find out where the problem is.

3) Check your code references, especially for the functions that have turned red when you hit “Upload”. Compare the syntax of your reference book to the syntax in your code editor here.

After you’ve fixed the bug and the code is working again, hit ‘Restore’ so you can see the code how it was before you fixed it. Is the bug obvious to you now? Reviewing like this will make it easier to find bugs in future programs!

Get stuck? Click on ‘Need a Hint?’ below. It will provide a clue about what’s wrong in this program.

/* Buggy:Play three tones on the speaker, on repeat*/ void setup(){ pinMode(2,OUTPUT); //Set the speaker as an OUTPUT } void loop(){ tone(2,500); //Play a tone of 500 hertz on pin 2 delay[1000); //Delay 1000 milliseconds (1 second) tone(2,700); //Play a tone of 700 hertz delay[1000); //Delay 1000 milliseconds tone(2,900}; //Play a tone of 900 hertz delay(1000); //Delay 1000 milliseconds before starting the loop code again } // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Some of the syntax in code looks very similar, like the bracket [ ],the curly brace { }, and the parentheses ( ). The arguments of a function should be surrounded by parentheses!

1_4 Beep 3 Tones on the Speaker

Beep 3 Tones on the Speaker

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


/* Play three tones on the speaker, on repeat*/ void setup(){ pinMode(2,OUTPUT); //Set the speaker as an OUTPUT } void loop(){ tone(2,500); //Play a tone of 500 hertz on pin 2 delay(1000); //Delay 1000 milliseconds (1 second) tone(2,700); //Play a tone of 700 hertz delay(1000); //Delay 1000 milliseconds tone(2,900); //Play a tone of 900 hertz delay(1000); //Delay 1000 milliseconds before starting the loop code again } // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

1_3 Blink Two Synced LEDs

Blink 2 Synced LED Lights

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


/* Blink two LEDs in sync */ void setup(){ pinMode(8,OUTPUT); //Set pin 8 to receive power pinMode(12,OUTPUT); //Set pin 12 to receive power } void loop(){ digitalWrite(8,HIGH);// turn on LED 8 digitalWrite(12,HIGH);//turn on LED 12 delay(1000);//delay 1000 milliseconds (1 second) digitalWrite(8,LOW);//turn off LED 8 digitalWrite(12,LOW);//turn off LED 12 delay(1000);//wait 1000 milliseconds before restarting the loop } //(c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

1_3_1 Blink 2 Synced LEDs Bug Hunt

Bug Hunt! Test your Troubleshooting.

Prefer listening over reading? Click the play button in the audio bar.

Here’s how Bug Hunts work:

We’ve taken the example code from the last project and inserted errors into it. These errors might be spelling problems, syntax, or we might have changed up how the program works altogether!

The goal of the Bug Hunt is to find and fix the errors so that when you upload the code, it runs just like the example code did on the project page.

Try these steps in order to solve a Bug Hunt:

1) Look over the code closely first, looking for anything that is out of place. We recommend you do this first to build up your ‘bug hunting instincts’.

2) Press ‘Upload the Code’ with your board plugged in and the circuit built. The code won’t work, but it will show you the errors that the computer found - these will pop up in a box just below the code editor. These clues are sometimes vague or confusing, but they may help you find out where the problem is.

3) Check your code references, especially for the functions that have turned red when you hit “Upload”. Compare the syntax of your reference book to the syntax in your code editor here.

After you’ve fixed the bug and the code is working again, hit ‘Restore’ so you can see the code how it was before you fixed it. Is the bug obvious to you now? Reviewing like this will make it easier to find bugs in future programs!

Get stuck? Click on ‘Need a Hint?’ below. It will provide a clue about what’s wrong in this program.

/* Buggy: Blink two LEDs in sync */ void setup(){ pinMode(8,OUTPUT); //Set pin 8 to receive power pinMode(12,OUTPUT); //Set pin 12 to receive power } void loop(){ digitalWrite(8,HIGH); // turn on LED 8 digitalWrite(12,HIGH) //turn on LED 12 delay(1000); //delay 1000 milliseconds (1 second) digitalWrite(8,LOW) //turn off LED 8 digitalWrite(12,LOW); //turn off LED 12 delay(1000);//wait 1000 milliseconds before restarting the loop } //(c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Functions end with a semicolon ( ; ). If one is missing, you'll have problems!

1_2 Buzz the Motor

Buzz the Vibration Motor

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


/* Buzz Code Lab Mini's motor on and off once per second */ void setup(){ pinMode(3,OUTPUT); //Set the motor as an output } void loop(){ digitalWrite(3,HIGH); //Turn on pin 3 delay(1000); //Wait 1000 milliseconds (1 second) digitalWrite(3,LOW); //Turn off pin 3 delay(1000); //Wait 1000 milliseconds before restarting the loop code } //(c)2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

1_1 Single Beep the Speaker

Single Speaker Beep

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


/* Beep a tone one time. Unplug and replug your power cable to hear it again! */ void setup(){ pinMode(2,OUTPUT); //Set pin 2 to receive power tone(2,400); //Send a tone of 400 hertz (hz) to the speaker delay(1000); //Delay 1000 milliseconds (1 second) with the tone playing noTone(2); //Turn off any tones playing } void loop(){} //Nothing in the loop, so no code will repeat // (c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

1_0_1 Blink Bug Hunt

Blink Bug Hunt! Test your Troubleshooting.

Prefer listening over reading? Click the play button in the audio bar.

Here’s how Bug Hunts work:

We’ve taken the example code from the last project (in this case, Blink) and inserted errors into it. These errors might be spelling problems, syntax, or we might have changed up how the program works altogether!

The goal of the Bug Hunt is to find and fix the errors so that when you upload the code, it runs just like the example code did on the project page.

Try these steps in order to solve a Bug Hunt:

1) Look over the code closely first, looking for anything that is out of place. We recommend you do this first to build up your ‘bug hunting instincts’.

2) Press ‘Upload the Code’ with your board plugged in and the circuit built. The code won’t work, but it will show you the errors that the computer found - these will pop up in a box just below the code editor. These clues are sometimes vague or confusing, but they may help you find out where the problem is.

3) Check your code references, especially for the functions that have turned red when you hit “Upload”. Compare the syntax of your reference book to the syntax in your code editor here.

After you’ve fixed the bug and the code is working again, hit ‘Restore’ so you can see the code how it was before you fixed it. Is the bug obvious to you now? Reviewing like this will make it easier to find bugs in future programs!

Get stuck? Click on ‘Need a Hint?’ below. It will provide a clue about what’s wrong in this program.

/* Buggy: Blink LED 8 on and off */ void setup(){ pinMode(8,OUTPUT); //Set LED 8 to receive power } void loop(){ digitalWrite(8,HIGH); //Turn on LED 8 delay(1000); //Wait 1000 milliseconds (1 second) digitalWRITE(8,LOW); //Turn off pin 8 delay(1000); //Wait 1000 milliseconds before restarting the loop code } //(c) 2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Check the capitalization of the words. Most code follows very strict rules about which words or letters are capitalized, and the computer won't recognize a command that isn't capitalized correctly!

1_0 Blink an LED Light

Blink an LED Light

Code

The code in the editor below is ready to run! Plug Code Lab Mini in to your computer's USB port with the cable and hit 'Upload Your Code!' to see what it does. Change something in the code, like a delay or pin number. Try to add something new to the program - it's yours to tinker with! You can always press the 'Restore' button to return the code to the working example.


/* Blink LED 8 on and off */ void setup(){ pinMode(8,OUTPUT); //Set pin 8 to receive power } void loop(){ digitalWrite(8,HIGH); //Turn on LED 8 delay(1000); //Wait 1000 milliseconds (1 second) digitalWrite(8,LOW); //Turn off LED 8 delay(1000); //Wait 1000 milliseconds before restarting the loop code } //(c)2023 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!