I am trying to create a program that would allow a user to create a colour using 3 level faders for each of the rgb channels. Once a colour has been created it should ask the user to name the colour. Scroll through letters using the red fader. Use save button to advance cursor. Once colour has been named save a text file to a sd card as "Colourname.txt". In the file store the RGB values as "R,red value,G,green value,B,blue value" ie. "R,134,G,255,B,003".
I have some of the code fleshed out but am a little lost on how to name the file.
Any help would be greatly appreciated. Code is attached
You will probably get more help if you post your code here rather than as an attachment. When you do that please use [code]code goes here[/code] tags around the code.
/*
This program should allow the user to "create" a colour using the RGB potentiometers.
Once a colour has been created, ask the user to name the colour. Scroll through letters using the red pot.
Use save button to advance cursor. Once colour has been named save a text file to a sd card as "Colourname.txt".
In the file store the RGB values as "R,r,G,g,B,b" ie. "R,134,G,255,B,003"
*/
#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //update to use other pins
//LED Pins
int RLed = 3;
int GLed = 5;
int BLed = 6;
//Level Pots Pins
int RFad = A0;
int GFad = A1;
int BFad = A2;
//LED Level Variables
long r = 0;
long g = 0;
long b = 0;
int num1 = 0;
int savebutton = 13;
char alpha = 'a';
char alphabet[] = {"abcdefghijklmnopqrstuvwxyz0123456789-_#ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; // obviously incorrect. Not sure how to do this
void setup() {
pinMode(RLed, OUTPUT);
pinMode(GLed, OUTPUT);
pinMode(BLed, OUTPUT);
pinMode(RFad, INPUT);
pinMode(GFad, INPUT);
pinMode(BFad, INPUT);
pinMode(savebutton, INPUT_PULLUP);
lcd.begin(16,2);
}
void loop() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("R******G*******B");
r = (analogRead(RFad)/4);
g = (analogRead(GFad)/4);
b = (analogRead(BFad)/4);
lcd.setCursor(0,1);
lcd.print(r);
lcd.setCursor(7,1);
lcd.print(g);
lcd.setCursor(13,1);
lcd.print(b);
analogWrite(RLed, r);
analogWrite(GLed, g);
analogWrite(BLed, b);
delay(28);
int save = digitalRead(savebutton);
if (save = LOW) {
saveit();
}
}
void saveit(){
analogWrite(RLed, r);
analogWrite(GLed, g);
analogWrite(BLed, b);
num1 = analogRead(RFad);
num1 = map(num1, 0, 1023, 0, 65);
alpha = 'alphabet.charAt(num1)';
lcd.setCursor(0, 1);
lcd.print("R******G*******B");
lcd.setCursor(0,1);
lcd.print(r);
lcd.setCursor(6,1);
lcd.print(g);
lcd.setCursor(12,1);
lcd.print(b);
lcd.clear();
lcd.print("Name Colour");
lcd.print(alpha);
}
Not really understanding what is wrong with this? Some explanation would be greatly appreciated. In the initialization of the inputs I declared the save button as an input with a pull up resistor so would this not trigger the save function when the button was pressed and the pin pulled to ground?
AWOL:
Then fix this
alpha = 'alphabet.charAt(num1)';
Again, not really sure what is wrong with this? I am thinking its the apostrophes? Looking for help on how to fix this or even a link to some reference material that may help.
Oh wow, I should have known that :P, Thank you CrossRoads!
When I try and run this program after making the suggested edits I get the following error:
Colour_Mixer.ino: In function 'void saveit()':
Colour_Mixer.ino:71:18: error: request for member 'charAt' in 'alphabet', which is of non-class type 'char [66]'
request for member 'charAt' in 'alphabet', which is of non-class type 'char [66]'
I think it has something to do with this horrible string array:
char alpha = 'a'; //set the intial letter to lower case "a"
char alphabet[] = {"abcdefghijklmnopqrstuvwxyz0123456789-_#ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; //store the alphabet, lowercase and uppercase as well as some numbers and characters. obviously incorrect. Not sure how to do this
and recalling this code at this point:
void saveit(){
analogWrite(RLed, r);
analogWrite(GLed, g);
analogWrite(BLed, b);
num1 = analogRead(RFad); //read the value from the red potentiometer
num1 = map(num1, 0, 1023, 0, 65); //map the value read to the amount of characters in the array
alpha = alphabet.charAt(num1); //put a character from the array into the variable "alpha"
lcd.setCursor(0, 1);
lcd.print("R******G*******B");
lcd.setCursor(0,1);
lcd.print(r);
lcd.setCursor(6,1);
lcd.print(g);
lcd.setCursor(12,1);
lcd.print(b);
lcd.clear();
lcd.print("Name Colour");
lcd.print(alpha);
}
So just to be clear, if i was going to use the array index, (because I have no idea how to work with ASCII code) I would need to reformat my text in the array to match the example: