Go Down

Topic: Help with values and calling them up. (Read 1 time) previous topic - next topic

Temo

Apr 11, 2010, 05:47 pm Last Edit: Apr 11, 2010, 05:48 pm by itstemo1 Reason: 1
I am trying to make something using the Time library and the Ledcontroller library to turn a certain led on a certain given second.

I am not sure how variables and values work. And i worst don't know how to call one up.

The time library uses "second()" to determine current second.
For the ledcontroller i use the command "lc.setLed(0,2,6,true);" to turn on the led on the row 2, column 6

So i wanted to do something like

Code: [Select]

Librarys blah blah blah

int 01 = 2,6

void setup(){
blah blah
}

void loop(){
   lc.setLed(0,"second()",true);
}


I just don't understand C. Anyone can sheed some light on to my problem. I was at LadyAda/Adafruit website taking the tutorials.

AWOL

#1
Apr 11, 2010, 05:55 pm Last Edit: Apr 11, 2010, 05:56 pm by AWOL Reason: 1
Quote
int 01 = 2,6


Well, variable names have to start with a letter or an underscore.

In C, a decimal point is a full-stop (period), not a European comma, and you can't asssign floating-point values to an "int" variable. (well, you can, but you'll only get the integer part).

You also need a semicolon to terminate every statement.

I'd start off simple, with some of the examples in the learning section, then pick them apart to see how C works.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Temo

So now i get this "Illegal Const Char to Char conversion"

Code: [Select]
Librarys blah blah blah

// _## = seconds and "#,#" is the row and column value for the leds
const char _01 = "0,0";  //At second 01 the value will be 0,0
const char _02 = "0,1";  //At second 02 the value will be 0,1
const char _03 = "0,2";
.....
const char _58 = "7,3";
const char _59 = "7,4";  //At second 59 the value will be 7,1
const char _00 = "7,5";  //At second 00 the value will be 7,2


void setup(){
blah blah
}

void loop(){
   lc.setLed(0,"_second()",true);
}


also at the bottom where "lc.setLed(0,"_second()",true);" how can i make the second() to call up my variable and for the entire thing can work.

Sorry. i am a extreme n00b.

PaulS

A char can hold one character. A char array can hold more than one character.

A two dimensional array would solve your problem neatly. The first value would range from 0 to 59, and would be defined by the output from seconds. The second value would be a fixed size (4, in your case).

Code: [Select]
char stuff[60][4] = {"0,0", "0,1", "0,2", ... , "7,3", "7,4", "7,5"};

But, then:

Code: [Select]
char *ptr = stuff[second()];

would result in ptr = "7,3" when second() returned 57, which would need to be parsed (using strtok) and converted to integers (using atoi) to get the integer values that the LCD controller function is looking for.

You could use a 3 dimensional integer array.

Temo

Well i am making some progress. Thank you

To work with this i try to debug it using the Serial Monitor.
My problem is that i get this Æ thingy appearing on my output for ptss and ptst. I bolded the main problem.

Code: [Select]

libarary BLAH BLAh

char sec2[60][1] = {
0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
7, 7}; //Tables

char sec1[60][1] = {
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1}; //Tables

void setup()  {
blah blah blah for serial output
}

void digitalClockDisplay(){
 Serial.print(second());  // digital clock display of the time
 Serial.print(" ");
 Serial.print(*ptss); //Displays one number of the first Array
 Serial.print(",");
 Serial.print(*ptst); //Displays one number of the second Array
 Serial.println();
}

void loop(){    
   digitalClockDisplay(); //Outputs the stuff in digitalClockDisplay on the serial monitor
   char *ptss = sec1[second()];
   char *ptst = sec2[second()];
  // lc.setLed(0,*ptss,true);
 }

 delay(1000);
}


I should be getting things like

01 00,01
02 00,02
..
59 07,00
00 07,01

but i get
01 Æ,Æ
02 Æ,Æ
...
59 Æ,Æ
00 Æ,Æ

Go Up