I’ve copied the code from the “Experiment 4: Color Selector” program exactly as is and uploaded to the Redboard. I’ve verified the wiring several times as well. But the code just does not seem to upload. The simple D7 LED program uploads easily and works (i’ve tried several blink lengths to verify this).
What could be going wrong? This is frustrating me no end!
/* SparkFun Inventor's Kit for Photon
Experiment 4 - Part 1
This sketch was written by SparkFun Electronics
Ben Leduc-Mills
August 31, 2015
https://github.com/sparkfun
This is an example sketch using buttons and a potentiometer to change the color and brightness of the Photon RedBoard onboard LED.
Development environment specifics:
Particle Build environment (https://www.particle.io/build)
Particle Photon RedBoard
Released under the MIT License(http://opensource.org/licenses/MIT)
*/
int redButton = D2; // declare variable for red button
int greenButton = D3; // declare variable for green button
int blueButton = D4; // declare variable for blue button
int potentiometer = A0; // declare variable for potentiometer
int colorMode; // declare variable to keep track of color
int potValue = 0; // // declare variable for the value of the potentiometer
void setup() {
RGB.control(true); // command to control the RGB led on the Photon
// buttons need an internal pullup resistor - see below for notes
pinMode(redButton, INPUT_PULLUP);
pinMode(greenButton, INPUT_PULLUP);
pinMode(blueButton, INPUT_PULLUP);
pinMode(potentiometer, INPUT); // potentiometers are an analog input
colorMode = 0;
}
void loop() {
// change colorMode variable depending on which button was pressed
if(digitalRead(redButton) == LOW) { // double equals checks for equality
colorMode = 1; // single equals is for assigning a new value to the variable
}
if(digitalRead(greenButton) == LOW) {
colorMode = 2;
}
if(digitalRead(blueButton) == LOW) {
colorMode = 3;
}
// read from the potentiometer, divide by 16 to get a number we can use for a color value
potValue = analogRead(potentiometer)/16;
changeColor(colorMode, potValue); // call changeColor function
}
// changeColor takes a color mode and a potentiometer value and changes the color and brightness of the Photon RGB LED
void changeColor(int _colorMode, int _potValue) {
if(_colorMode == 1) {
RGB.color(_potValue, 0, 0);
}
if(_colorMode == 2) {
RGB.color(0, _potValue, 0);
}
if(_colorMode == 3) {
RGB.color(0, 0, _potValue);
}
else if(colorMode == 0) {
RGB.color(0,0,0);
}
}
Which build environment are you using? Particle Build (Web IDE), Particle Dev (Atom IDE), or Particle CLI? If using Dev, could you take a screenshot of the window?
Yes, did all that. Also, FYI, code loads OK onto the board. For example, the simple blinking program loads and works. It appears that there is some issue with this code…this code compiles and uploads successfully, but does not run. Even the simple led blink piece of the code is not running.
Thanks for the picture. I think there are two things going on here: The first is that Particle Dev does not build the file that’s in the frontmost tab. It builds all of the files in the directory the the file you first opened is contained in. So pretty much you need to make a separate directory for each project within your “Sparkfun Projects” directory, then put a separate .ino file in each directory.
The second is that I don’t think that RGB Buttons has a filename extension. This is why you’re not getting a build error; it’s being treated as a text file not a source code file and is being ignored. That’s why the syntax highlighting (other than links) is missing.
OK, thanks. It certainly did not have an extension, so I saved it with a .ino extension in a new folder with the same filename. Now, when I compile, I get a “build didn’t produce binary” error.
Thanks man! I went back and ensured that the other .ino program was not in the Particle Dev environment when compiling the RGB code and it worked great this time! Thanks again!