0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« on: April 11, 2010, 10:47:15 am » |
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 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.
|
|
|
|
« Last Edit: April 11, 2010, 10:48:57 am by itstemo1 »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19001
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: April 11, 2010, 10:55:52 am » |
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.
|
|
|
|
« Last Edit: April 11, 2010, 10:56:11 am by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #2 on: April 11, 2010, 11:32:14 am » |
So now i get this "Illegal Const Char to Char conversion" 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.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #3 on: April 11, 2010, 11:48:13 am » |
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). char stuff[60][4] = {"0,0", "0,1", "0,2", ... , "7,3", "7,4", "7,5"}; But, then: 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.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #4 on: April 11, 2010, 01:27:38 pm » |
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. 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 Æ,Æ
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19001
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: April 11, 2010, 01:29:51 pm » |
Serial.print(*ptss); I don't see where or how you declared and initialised this pointer. Could you post your real code (minus the "blah blah"s)? (You may be missing a "DEC" or two)
|
|
|
|
« Last Edit: April 11, 2010, 01:32:06 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #6 on: April 11, 2010, 01:45:20 pm » |
#include <LedControl.h> #include <Time.h> #define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits #define TIME_HEADER 'T' // Header tag for serial time sync message #define TIME_REQUEST 7 // ASCII bell character requests a time sync message
LedControl lc=LedControl(12,11,10,1);
char *ptss; char *ptst; 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}; 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};
void setup() { Serial.begin(9600); setSyncProvider( requestSync); //set function to call when sync required Serial.println("Waiting for sync message"); /* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */ lc.shutdown(0,false); /* Set the brightness to a medium values */ lc.setIntensity(0,10); /* and clear the display */ }
void digitalClockDisplay(){ // digital clock display of the time Serial.print(second()); Serial.print(" "); Serial.print(*ptss); Serial.print(","); Serial.print(*ptst); Serial.println(); }
void printDigits(int digits){ // utility function for digital clock display: prints preceding colon and leading 0 Serial.print(":"); if(digits < 10) Serial.print('0'); Serial.print(digits); }
void processSyncMessage() { // if time sync available from serial port, update time and return true while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits char c = Serial.read() ; Serial.print(c); if( c == TIME_HEADER ) { time_t pctime = 0; for(int i=0; i < TIME_MSG_LEN -1; i++){ c = Serial.read(); if( c >= '0' && c <= '9'){ pctime = (10 * pctime) + (c - '0') ; // convert digits to a number } } setTime(pctime); // Sync Arduino clock to the time received on the serial port } } }
time_t requestSync() { Serial.print(TIME_REQUEST,BYTE); return 0; // the time will be sent later in response to serial mesg }
void loop(){ if(Serial.available() ) { processSyncMessage(); } if(timeStatus()!= timeNotSet) { digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh digitalClockDisplay(); char *ptss = sec1[second()]; char *ptst = sec2[second()]; // lc.setLed(0,*ptss,true); }
delay(1000); }
I am sorry. I just didn't want to have like a very long annoying post
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19001
I don't think you connected the grounds, Dave.
|
 |
« Reply #7 on: April 11, 2010, 01:46:48 pm » |
So, you didn't initialise it. char *ptss;
You need to remove the second declaration of the pointer for this construct to work. You need to read about scope rules.
|
|
|
|
« Last Edit: April 11, 2010, 01:48:34 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #8 on: April 11, 2010, 02:32:37 pm » |
I still don't get it
I read some scoping rules, but it got really advance. This is my first time doing C++
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #9 on: April 11, 2010, 03:53:11 pm » |
You have a global variables named ptss and ptst.
In loop, you declare local variables with the same names, and initialize them. That has no effect on the global variables.
At the end of the if block in which the local variables ptss and ptst are declared, they go out of scope.
The function digitalClockDisplay references the global variables, which have never been initialized.
Even if you remove the declaration statements in the if block in loop, so that ptss and ptst refer to the global variables, the initialization does not take place until after the call to digitalClockDisplay.
Also, sec1[0][0] is set to 0, which is not the same as '0'.
Finally, since the stated goal was to use the values that ptss and ptst point to as arguments to the lc function, which requires integers, it seems to me that you should declare sec1 and sec2 to be integer arrays.
Last, but not least, there is a pattern to the values in sec1 and sec2 that means that you don't need to store them in an array.
sec1 = 60 % 8; sec2 = 60 / 8;
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #10 on: April 11, 2010, 06:35:16 pm » |
yeah... no idea...
could someone do some of the work for me. Except for the array. I would like to be able to change that if i need to.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #11 on: April 12, 2010, 01:41:55 am » |
You're trying to run before you can walk.
Start looking at some of the tutorials, and work through them. Try modifying them and expanding them.
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #12 on: April 14, 2010, 06:57:04 pm » |
Thanks guys... you made me learn some stuff by myself.
You guys are my FRIENDS now...
i did manage to get it work. HORRAY!!!
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #13 on: April 15, 2010, 03:45:03 am » |
And you are our friend for sticking with it, and not giving up!
Congratulations! 8-)
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
|