Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

AI Helps Debug Arduino Code

Jeel Kathiriya
You will have to help me with my assignment: Here is the detailed assignment instruction
provided by professor: Assignment – AI & Arduino Coding: Artificial Intelligence is quickly
becoming an influential part of our lives. From creative writing to creating art, humans are
continuing to expand the integration of AI into many fields. Along with the development of AI
come challenging questions on topics such as plagiarism, bias, and false information. In this
assignment, students will be given the chance to work with AI. Students will be given a simple
but broken code. The code should flash the 10 RGB LEDs included on the Adafruit Circuit
Playground Express (CPE) board Red, Green and then Blue in a chasing pattern. Students must
use ChatGPT as a tool to help them debug the code. The goal of this assignment is to introduce
AI as a tool for learning and experimenting but also to begin thinking about the ethical questions
surrounding AI. Don’t worry if you are not completely successful in fixing the code as the
important part of this assignment is to introduce students to the idea of using AI as a tool to help
with the learning of coding and troubleshooting. A 500 to 1000 word reflection will make up the
majority of the assignment along with your final code. You MUST source ChatGPT in your post
on your portfolio. When writing your reflection, consider the following: - What did AI do for
you in this assignment? - Do you feel you contributed meaningfully to this assignment? - Was
this assignment made easier or more difficult with the integration of AI? - How does using AI
compare to using traditional coding forums when asking for help? - Is the use of AI in this
capacity ethical? - Did AI ease any concerns about possibly coding for the first time? Upload 6
screenshots of the process of fixing the code and working with ChatGPT, a short video of the
Adafruit (CPE) working, and your reflection to your website/portfolio. Tips: The majority of
marks for this assignment come from the reflection. When writing your reflection, think about
the process of coding with the help of ChatGPT. If you are new to coding, was it helpful? If you
are experienced in coding, how did it do? What is the significance of ChatGPT with respect to
coding? Think about the questions included in this assignment. Have fun experimenting! While
we are trying to fix the code, getting the perfect result is not worth stressing over. ChatGPT
Link: Introducing ChatGPT (openai.com) Downloads: Arduino IDE Software | Arduino Useful
Links: Arduino Website Code Definitions and Descriptions:
https://www.arduino.cc/reference/en/ Colour Picker/ Converter to RGB Codes:
https://www.rapidtables.com/convert/color/hex-to-rgb.html Adobe Colour Wheel:
https://color.adobe.com/create/color-wheel Adafruit_CPE_LED_Code_Broken.zip
Adafruit_CPE_LED_Code_Broken.zip30 May 2024, 10:12 AM
Adafruit_CPE_LED_TEST_Code.zip Adafruit_CPE_LED_TEST_Code.zip30 May 2024, 9:19
AM Assignment 4 Grading Rubric (1).pdf Assignment 4 Grading Rubric (1).pdf3 June 2024,
8:25 AM Please remember above provided information and let me know when you are ready for
the broken code.
ChatGPT

I'm ready to help you with your assignment. Please go ahead and provide the broken code so we
can start debugging it with the help of ChatGPT. Once we have the code, we can proceed step by
step to identify and fix the issues, ensuring we document the process along the way for your
reflection.

Jeel Kathiriya
/* Written by Brandon Watson for the AI & Arduino Coding Assignment in CTCH 110 at the
University of Regina. The following code is designed to use the 10 onboard RGB LEDS on an
Adafruit Circuit Playground Express in a certain sequence. The sequence is: Red - chasing
pattern (delay between pixel 100 miliseconds) from LED 1 to 10 until all are red Pause - keep all
LEDs red for 1 second Green - change LEDs from red to green in a chasing pattern (delay
between pixel 100 miliseconds) from LED 1 to 10 until all are green Pause - keep all LEDs green
for 1 second Blue - change LEDs from green to blue in a chasing pattern (delay between pixel
100 miliseconds) from LED 1 to 10 until all are blue Pause - keep all LEDs blue for 1 second
return to start This sequence should repeat indefinitely. */ #include <Adafruit_NeoPixel.h> //
Include the NeoPixel library #define PIN 8 // Pick the pin on the Adafruit CPE that the LED is
connected to (in this case, pin 8) Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN,
NEO_GRB + NEO_KHZ800); void setup() { strip.begin(); // Initialize the LED pixels
strip.show(); // Initialize the pixels to 'off' strip.setBrightness(25) // We are setting the brightness
to 25% as the LEDs are too bright to look a at 100% } void loop() { // strip.setPixelColor: first
number = pixel number | second number = red brightness (0 - 255) | third number = green
brightness (0 - 255) | fourth number = blue brightness (0 - 255) // strip.setPixelColor: Example:
strip.setPixelColor(pixel 1, Red, Green, Blue) // strip.setPixelColor: Pixel 1 should be '0' because
when coding, the count starts at 0 for(int i=0;i<10;i++){ //This is a for loop that starts at the first
LED, changes it to red and repeats until all LEDs are red - 'i' starts at 0 and counts until it = 9
which means it has repeated 10 times strip.setPixelColor(i, 250, 250, 0); strip.show(); //Function
to tell the Adafruit CPE to display the LED change delay(500); //Delay for 100 miliseconds }
delay(2000); //Delay for 1000 miliseconds (1 second) for(int i=0;i<10;i++)
{ strip.setPixelColor(i, 250, 0, 250); strip.show() delay(50); //Delay for 100 miliseconds }
delay(5000); //Delay for 1000 miliseconds (1 Second) for(int i=0;i<10;i++)
{ strip.setPixelColor(i, 79, 201, 230); strip.show(); delay(600) //Delay for 100 miliseconds }
delay(50); //Delay for 1000 miliseconds (1 second) Remember above code and wait for my
further instruction

ChatGPT
Great! Let's begin by identifying and fixing the issues in the provided code. I'll guide you
through the debugging process step by step, using ChatGPT to help identify potential errors and
their solutions.

Step 1: Identifying Syntax Errors

First, let's look for syntax errors that might prevent the code from compiling.

1. Missing semicolon after strip.setBrightness(25) in the setup function.


2. Incorrect delay values and comments. The comments state delays in milliseconds, but the
values seem off.
3. Missing closing brace for the loop function.
4. Misformatted delays and incorrect strip.show() calls.

Here's a corrected version of your code:

cpp
Copy code
#include <Adafruit_NeoPixel.h> // Include the NeoPixel library

#define PIN 8 // Pick the pin on the Adafruit CPE that the LED is connected to (in this case, pin
8)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin(); // Initialize the LED pixels
strip.show(); // Initialize the pixels to 'off'
strip.setBrightness(25); // We are setting the brightness to 25% as the LEDs are too bright to
look at 100%
}

void loop() {
// Red chasing pattern
for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set LED to red
strip.show(); // Function to tell the Adafruit CPE to display the LED change
delay(100); // Delay for 100 milliseconds
}
delay(1000); // Pause for 1 second
// Green chasing pattern
for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set LED to green
strip.show(); // Function to tell the Adafruit CPE to display the LED change
delay(100); // Delay for 100 milliseconds
}
delay(1000); // Pause for 1 second

// Blue chasing pattern


for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 0, 0, 255); // Set LED to blue
strip.show(); // Function to tell the Adafruit CPE to display the LED change
delay(100); // Delay for 100 milliseconds
}
delay(1000); // Pause for 1 second
}

Step 2: Documenting the Process

Take screenshots of the code before and after making these changes. This will help you
document your debugging process for the reflection part of your assignment.

Step 3: Testing the Code

Upload the corrected code to your Adafruit Circuit Playground Express (CPE) board using the
Arduino IDE. Verify if the LEDs perform the chasing pattern as expected (red, green, blue with
pauses).

Step 4: Reflection

As part of your reflection, you can discuss the following points:

 What did AI do for you in this assignment? AI helped identify syntax errors and
provided a corrected version of the code, making the debugging process faster and more
efficient.
 Do you feel you contributed meaningfully to this assignment? Yes, you reviewed and
implemented the suggestions provided by AI, learning about common coding issues and
how to fix them.
 Was this assignment made easier or more difficult with the integration of AI? The
assignment was made easier with AI, as it provided instant feedback and solutions to
coding problems.
 How does using AI compare to using traditional coding forums when asking for
help? AI provides instant responses, whereas traditional coding forums may have a
delay. However, forums offer human insights and multiple perspectives.
 Is the use of AI in this capacity ethical? Using AI as a learning tool is ethical as long as
it is acknowledged and used to enhance understanding, not replace genuine learning
efforts.
 Did AI ease any concerns about possibly coding for the first time? Yes, AI can
provide a sense of guidance and support, reducing anxiety about coding errors and
helping beginners learn more confidently.

Step 5: Completing the Assignment

 Take 6 screenshots of the process: initial code, identifying errors, corrected code,
uploading code, running code, and final working setup.
 Record a short video of the CPE working with the corrected code.
 Write your reflection, incorporating the points discussed.
 Upload everything to your website/portfolio, and remember to credit ChatGPT in your
post.

If you have any more questions or need further assistance, feel free to ask!

Jeel Kathiriya
Here is the broken code that is not working correctly. Can you please help me identify any
syntax errors or issues with this code and provide suggestions on how to fix it?
ChatGPT
ChatGPT

Sure, let's go through your code and identify any syntax errors or issues. I'll provide suggestions
on how to fix them and then present the corrected version.

Step-by-Step Debugging

5. Include Statement and Library Initialization: The include statement and the
initialization of the NeoPixel library look correct.
6. setup Function:
o There is a missing semicolon at the end of strip.setBrightness(25).
7. loop Function:
o Inconsistent comments and delay values. Ensure comments match the actual code.
o Missing semicolon after strip.show() in the second loop.
o Incorrect delay values (check if they match the description).
o Missing semicolon at the end of the delay in the third loop.
o Missing closing brace for the loop function.

Corrected Code

Here is the corrected version of your code with the identified issues fixed:

cpp
Copy code
#include <Adafruit_NeoPixel.h> // Include the NeoPixel library

#define PIN 8 // Pick the pin on the Adafruit CPE that the LED is connected to (in this case, pin
8)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin(); // Initialize the LED pixels
strip.show(); // Initialize the pixels to 'off'
strip.setBrightness(25); // We are setting the brightness to 25% as the LEDs are too bright to
look at 100%
}

void loop() {
// Red chasing pattern
for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set LED to red
strip.show(); // Function to tell the Adafruit CPE to display the LED change
delay(100); // Delay for 100 milliseconds
}
delay(1000); // Pause for 1 second

// Green chasing pattern


for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set LED to green
strip.show(); // Function to tell the Adafruit CPE to display the LED change
delay(100); // Delay for 100 milliseconds
}
delay(1000); // Pause for 1 second

// Blue chasing pattern


for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 0, 0, 255); // Set LED to blue
strip.show(); // Function to tell the Adafruit CPE to display the LED change
delay(100); // Delay for 100 milliseconds
}
delay(1000); // Pause for 1 second
}

Explanation of Changes

8. Fixed Missing Semicolons:


o Added a semicolon after strip.setBrightness(25) in the setup function.
o Added a semicolon after strip.show() in the second loop.
o Added a semicolon after delay(600) in the third loop.
9. Corrected Delay Values:
o Ensured all delays match the expected values as per the comments.
10. Added Missing Closing Brace:
o Added the missing closing brace for the loop function.

Next Steps

11. Take Screenshots:


o Capture screenshots of the code before and after making these changes to
document the debugging process.
12. Test the Code:
o Upload the corrected code to your Adafruit Circuit Playground Express (CPE)
board using the Arduino IDE.
o Verify that the LEDs perform the chasing pattern as described: Red, Green, Blue
with pauses.
13. Create a Reflection:
o Reflect on the experience of debugging the code with the help of AI, addressing
the questions provided in the assignment.
14. Complete the Assignment:
o Record a short video of the CPE working with the corrected code.
o Write your reflection and include the screenshots, video, and the final code.
o Upload everything to your website/portfolio, making sure to credit ChatGPT.
If you need any further assistance or have additional questions, feel free to ask!

Jeel Kathiriya
Can you provide me with error message that I would have received before implementing above
code changes?

ChatGPT

Certainly! Based on the errors identified in your original code, here's a list of likely error
messages you would have encountered before making the necessary corrections:

15. Missing Semicolon after strip.setBrightness(25):

plaintext
Copy code
error: expected ';' before '}' token
strip.setBrightness(25)
^

16. Missing Semicolon after strip.show() in the second loop:

plaintext
Copy code
error: expected ';' before 'delay'
strip.show()
^

17. Missing Semicolon after delay(600) in the third loop:

plaintext
Copy code
error: expected ';' before '}' token
delay(600) //Delay for 100 miliseconds
^

18. Missing Closing Brace for loop function:

plaintext
Copy code
error: expected '}' at end of input

Given these issues, here’s how the error messages might appear collectively:

plaintext
Copy code
Arduino: 1.8.x (Windows 10), Board: "Adafruit Circuit Playground Express"

sketch_jun11a:10: error: expected ';' before '}' token


strip.setBrightness(25)
^
sketch_jun11a:27: error: expected ';' before 'delay'
strip.show()
^
sketch_jun11a:35: error: expected ';' before '}' token
delay(600) //Delay for 100 miliseconds
^
sketch_jun11a:38: error: expected '}' at end of input
}

exit status 1
expected ';' before '}' token

These error messages would guide you to the locations in your code where corrections are
needed. Once you fix these issues by adding the missing semicolons and closing brace, the code
should compile successfully.

Jeel Kathiriya
What are some things that I have to consider when we debug the code or an error.

ChatGPT

When debugging code or an error, several key considerations can help ensure a systematic and
effective approach. Here are some important factors to consider:

1. Read the Error Message Carefully

 Error Type: Understand what type of error it is (syntax, runtime, logical).


 Line Number: Check which line the error message is pointing to.
 Error Description: Read the description of the error for clues on what might be wrong.

2. Understand the Code

 Code Flow: Make sure you understand the overall flow of the code.
 Functionality: Know what each part of the code is supposed to do.
 Dependencies: Be aware of any libraries or external dependencies being used.

3. Check for Common Issues

 Syntax Errors: Look for missing semicolons, unmatched braces, and other syntax issues.
 Variable Scope: Ensure variables are declared and used within the correct scope.
 Function Calls: Verify that functions are called correctly and parameters are passed as
expected.

4. Use Debugging Tools

 Serial Monitor (for Arduino): Print out values to understand what the code is doing at
various points.
 Debugging Breakpoints: Use breakpoints to pause execution and inspect the state of the
program.

5. Test Incrementally

 Small Changes: Make small, incremental changes to the code and test frequently.
 Isolate Issues: Try to isolate the part of the code causing the problem.

6. Check Logic and Flow

 Logical Errors: Ensure that the code logic aligns with the intended behavior.
 Control Structures: Check loops and conditional statements for correctness.

7. Consult Documentation and Resources

 API Documentation: Refer to the documentation for libraries and functions being used.
 Forums and Communities: Look for similar issues on forums like Stack Overflow or
the Arduino community.
8. Use Clear and Descriptive Naming

 Variable Names: Use descriptive names for variables and functions to make the code
easier to understand.
 Comments: Add comments to explain complex or important parts of the code.

9. Understand Hardware Considerations (for Arduino)

 Pin Configuration: Ensure pins are correctly configured and used.


 Power Supply: Verify that the hardware components are receiving appropriate power.
 Connections: Check physical connections and wiring.

10. Reflect and Learn

 Understand the Fix: Make sure you understand why the fix works.
 Learn from Mistakes: Reflect on what caused the error and how to avoid it in the future.

Example: Applying These Principles to Your Code

19. Reading Error Messages:


o You would see messages pointing to specific lines where semicolons are missing.
20. Understanding the Code:
o Know that the code aims to create a chasing LED pattern on an Adafruit Circuit
Playground Express.
21. Checking Common Issues:
o Identified missing semicolons and a missing closing brace.
22. Using Debugging Tools:
o Using the Arduino IDE's error messages as a guide.
23. Testing Incrementally:
o Fix one error at a time and recompile to see if new errors emerge.
24. Checking Logic and Flow:
o Ensure that the LED pattern logic is correctly implemented in the loops.
25. Consulting Documentation:
o Refer to the Adafruit NeoPixel library documentation to ensure correct usage of
functions.
26. Clear and Descriptive Naming:
o Ensure variables and functions have descriptive names (e.g., strip for the
NeoPixel object).
27. Hardware Considerations:
o Verify that the correct pin is used and LEDs are connected properly.
28. Reflect and Learn:
 Understand the importance of syntax and why specific errors occurred.

By following these considerations, you can systematically approach debugging and improve the
quality and reliability of your code.

Jeel Kathiriya
I'm new to coding and this is my first time working with Arduino. Do you have any general tips
or advice on how I should approach debugging this broken code? What steps should I take to
methodically identify and fix the issues?

ChatGPT

Absolutely! Debugging for the first time can be a bit overwhelming, but with a structured
approach, it becomes much easier. Here are some general tips and a step-by-step guide on how to
methodically identify and fix issues in your Arduino code.

General Tips for Debugging

29. Stay Calm and Patient:


o Debugging can be frustrating, but staying patient and methodical is key.
30. Break Down the Problem:
o Break your code into smaller sections and test each one independently.
31. Use Documentation:
o Refer to the Arduino reference and library documentation frequently.
32. Ask for Help:
o Don’t hesitate to ask for help from online forums, classmates, or instructors.
33. Keep Learning:
o Each bug you encounter and fix is a learning opportunity.

Step-by-Step Guide to Debugging

1. Read and Understand the Code

 Carefully read through your code and understand what each part is supposed to do.
 Annotate parts of the code with comments to clarify their purpose.

2. Compile the Code

 Attempt to compile the code in the Arduino IDE.


 Note any error messages that appear; they are valuable clues.
3. Identify Syntax Errors

 Check the lines indicated by the error messages for syntax issues (e.g., missing
semicolons, unmatched braces).
 Fix these errors first, as they prevent the code from compiling.

4. Use Serial Monitor for Debugging

 Use the Serial Monitor to print out values and messages at different points in your code.
This helps you understand what the code is doing at runtime.
 For example, add Serial.begin(9600); in the setup function and Serial.println("message");
in the loop to track the flow.

5. Test Incrementally

 Make small changes one at a time and test the code frequently.
 This helps you isolate the specific change that causes any new issues.

6. Check Logical Errors

 Ensure the logic of your code makes sense. For example, verify that loops and
conditional statements do what you expect.
 Test parts of the code separately if possible.

7. Use Debugging Tools and Libraries

 Utilize any debugging tools or libraries provided by the Arduino ecosystem.

Debugging Your Code

Let's apply these steps to your code.

Step 1: Read and Understand the Code

 Your code is intended to light up the LEDs in a chasing pattern with different colors.

Step 2: Compile the Code

 If the code does not compile, it will produce error messages. Let's compile the original
code you provided:
cpp
Copy code
/*
Written by Brandon Watson for the AI & Arduino Coding Assignment in CTCH 110 at the
University of Regina.

The following code is designed to use the 10 onboard RGB LEDS on an Adafruit Circuit
Playground Express in a certain sequence. The sequence is:

Red - chasing pattern (delay between pixel 100 miliseconds) from LED 1 to 10 until all are red
Pause - keep all LEDs red for 1 second
Green - change LEDs from red to green in a chasing pattern (delay between pixel 100
miliseconds) from LED 1 to 10 until all are green
Pause - keep all LEDs green for 1 second
Blue - change LEDs from green to blue in a chasing pattern (delay between pixel 100
miliseconds) from LED 1 to 10 until all are blue
Pause - keep all LEDs blue for 1 second
return to start

This sequence should repeat indefinitely.


*/
#include <Adafruit_NeoPixel.h> // Include the NeoPixel library

#define PIN 8 // Pick the pin on the Adafruit CPE that the LED is connected to (in this case, pin
8)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin(); // Initialize the LED pixels
strip.show(); // Initialize the pixels to 'off'
strip.setBrightness(25); // We are setting the brightness to 25% as the LEDs are too bright to
look a at 100%
}

void loop() {
// Red chasing pattern
for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set LED to red
strip.show(); // Function to tell the Adafruit CPE to display the LED change
delay(100); // Delay for 100 milliseconds
}
delay(1000); // Pause for 1 second

// Green chasing pattern


for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set LED to green
strip.show(); // Function to tell the Adafruit CPE to display the LED change
delay(100); // Delay for 100 milliseconds
}
delay(1000); // Pause for 1 second

// Blue chasing pattern


for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 0, 0, 255); // Set LED to blue
strip.show(); // Function to tell the Adafruit CPE to display the LED change
delay(100); // Delay for 100 milliseconds
}
delay(1000); // Pause for 1 second
}

Step 3: Identify Syntax Errors

 Compile the code and address the following syntax errors:


o Missing semicolon after strip.setBrightness(25)
o Missing semicolon after strip.show() in the second loop
o Missing semicolon after delay(600) in the third loop
o Missing closing brace for the loop function

Step 4: Use Serial Monitor for Debugging

 Add serial prints to understand the flow. For example:


cpp
Copy code
void setup() {
Serial.begin(9600);
strip.begin();
strip.show();
strip.setBrightness(25);
Serial.println("Setup complete");
}

void loop() {
Serial.println("Starting red chase pattern");
// Red chasing pattern
for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 255, 0, 0);
strip.show();
delay(100);
}
delay(1000);
Serial.println("Red chase pattern complete");

// Green chasing pattern


Serial.println("Starting green chase pattern");
for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 0, 255, 0);
strip.show();
delay(100);
}
delay(1000);
Serial.println("Green chase pattern complete");

// Blue chasing pattern


Serial.println("Starting blue chase pattern");
for (int i = 0; i < 10; i++) {
strip.setPixelColor(i, 0, 0, 255);
strip.show();
delay(100);
}
delay(1000);
Serial.println("Blue chase pattern complete");
}

Step 5: Test Incrementally

 After fixing each error and adding serial prints, recompile and test the code. Verify that
the LEDs behave as expected.
Step 6: Check Logical Errors

 Ensure that the color values and delays match the intended sequence and pattern. Verify
each loop and delay in the context of the expected behavior.

Step 7: Use Debugging Tools and Libraries

 Utilize the Arduino IDE features such as auto-formatting and error highlighting to spot
issues.

Reflection on the Process

As you debug, take note of each error and your steps to fix it. This will help you write a detailed
reflection for your assignment, addressing the following points:

 What did AI do for you in this assignment?


 Do you feel you contributed meaningfully to this assignment?
 Was this assignment made easier or more difficult with the integration of AI?
 How does using AI compare to using traditional coding forums when asking for help?
 Is the use of AI in this capacity ethical?
 Did AI ease any concerns about possibly coding for the first time?

If you follow these steps and tips, you'll be well on your way to successfully debugging your
Arduino code. If you have any further questions or run into issues, feel free to ask!

Jeel Kathiriya
/* Written by Brandon Watson for the AI & Arduino Coding Assignment in CTCH 110 at the
University of Regina. The following code is designed to use the 10 onboard RGB LEDS on an
Adafruit Circuit Playground Express in a certain sequence. The sequence is: Red - chasing
pattern (delay between pixel 100 miliseconds) from LED 1 to 10 until all are red Pause - keep all
LEDs red for 1 second Green - change LEDs from red to green in a chasing pattern (delay
between pixel 100 miliseconds) from LED 1 to 10 until all are green Pause - keep all LEDs green
for 1 second Blue - change LEDs from green to blue in a chasing pattern (delay between pixel
100 miliseconds) from LED 1 to 10 until all are blue Pause - keep all LEDs blue for 1 second
return to start This sequence should repeat indefinitely. */ #include <Adafruit_NeoPixel.h> //
Include the NeoPixel library #define PIN 8 // Pick the pin on the Adafruit CPE that the LED is
connected to (in this case, pin 8) Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN,
NEO_GRB + NEO_KHZ800); void setup() { strip.begin(); // Initialize the LED pixels
strip.show(); // Initialize the pixels to 'off' // *****CODE ERROR***** //strip.setBrightness(25)
// We are setting the brightness to 25% as the LEDs are too bright to look a at 100%
strip.setBrightness(25); } void loop() { // strip.setPixelColor: first number = pixel number |
second number = red brightness (0 - 255) | third number = green brightness (0 - 255) | fourth
number = blue brightness (0 - 255) // strip.setPixelColor: Example: strip.setPixelColor(pixel 1,
Red, Green, Blue) // strip.setPixelColor: Pixel 1 should be '0' because when coding, the count
starts at 0 //***** RED SEQUENCE****** for(int i=0;i<=9;i++){ //This is a for loop that starts
at the first LED, changes it to red and repeats until all LEDs are red - 'i' starts at 0 and counts
until it = 9 which means it has repeated 10 times strip.setPixelColor(i, 255, 0, 0);
strip.show(); //Function to tell the Adafruit CPE to display the LED change // *****CODE
ERROR***** // delay(500); //Delay for 100 miliseconds delay(100); //Delay for 100
miliseconds } // *****CODE ERROR***** //delay(2000); //Delay for 1000 miliseconds (1
second) delay(1000); //Delay for 1000 miliseconds (1 second) //***** GREEN
SEQUENCE****** for(int i=0;i<=9;i++){ strip.setPixelColor(i, 0, 255, 0); strip.show(); //
*****CODE ERROR***** // delay(50); //Delay for 100 miliseconds delay(100); //Delay for
100 miliseconds } // *****CODE ERROR***** //delay(5000); //Delay for 1000 miliseconds (1
second) delay(1000); //Delay for 1000 miliseconds (1 Second) //***** BLUE
SEQUENCE****** for(int i=0;i<=9;i++){ strip.setPixelColor(i, 0, 0, 255); strip.show(); //
*****CODE ERROR***** //delay(600) //Delay for 100 miliseconds delay(100) //Delay for 100
miliseconds } // *****CODE ERROR***** //delay(50); //Delay for 1000 miliseconds (1
second) delay(1000); //Delay for 1000 miliseconds (1 second) }

Format Above code and comment the line where their is error. In next line add the correct code.
Remove unwanted comment.

ChatGPT

Certainly! Here is your code formatted correctly with the errors commented out and the correct
code added right below each error comment. Unnecessary comments have been removed.

cpp
Copy code
/*
Written by Brandon Watson for the AI & Arduino Coding Assignment in CTCH 110 at the
University of Regina.

The following code is designed to use the 10 onboard RGB LEDS on an Adafruit Circuit
Playground Express in a certain sequence. The sequence is:

Red - chasing pattern (delay between pixel 100 miliseconds) from LED 1 to 10 until all are red
Pause - keep all LEDs red for 1 second
Green - change LEDs from red to green in a chasing pattern (delay between pixel 100
miliseconds) from LED 1 to 10 until all are green
Pause - keep all LEDs green for 1 second
Blue - change LEDs from green to blue in a chasing pattern (delay between pixel 100
miliseconds) from LED 1 to 10 until all are blue
Pause - keep all LEDs blue for 1 second
return to start

This sequence should repeat indefinitely.


*/
#include <Adafruit_NeoPixel.h> // Include the NeoPixel library

#define PIN 8 // Pick the pin on the Adafruit CPE that the LED is connected to (in this case, pin
8)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin(); // Initialize the LED pixels
strip.show(); // Initialize the pixels to 'off'
//strip.setBrightness(25) // CODE ERROR: Missing semicolon
strip.setBrightness(25); // Correct code
}

void loop() {
// Red chasing pattern
for (int i = 0; i <= 9; i++) {
strip.setPixelColor(i, 255, 0, 0);
strip.show();
// delay(500); // CODE ERROR: Incorrect delay
delay(100); // Correct code
}
//delay(2000); // CODE ERROR: Incorrect delay
delay(1000); // Correct code

// Green chasing pattern


for (int i = 0; i <= 9; i++) {
strip.setPixelColor(i, 0, 255, 0);
strip.show();
// delay(50); // CODE ERROR: Incorrect delay
delay(100); // Correct code
}
//delay(5000); // CODE ERROR: Incorrect delay
delay(1000); // Correct code

// Blue chasing pattern


for (int i = 0; i <= 9; i++) {
strip.setPixelColor(i, 0, 0, 255);
strip.show();
//delay(600) // CODE ERROR: Missing semicolon
delay(100); // Correct code
}
//delay(50); // CODE ERROR: Incorrect delay
delay(1000); // Correct code
}

This code should now be correctly formatted and free of syntax errors. Each identified error has
been corrected appropriately.

Sign up to chat
Report content|Terms of use|Privacy policy|

You might also like