String and Array Confusion

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

String and Array Confusion

Postby bafil » Wed Apr 25, 2012 4:16 pm

Hello All

I am working on a POV clock that is giving me a hard time in the coding department. I am at a point where I have been able to get data from a RTC breakout board and store the values. I also have been able to assign those values to a predefined character set for the POV. I am able to display the Hours values, the minutes values, and the seconds values. HOWEVER, I can only display them individually and not all at once. I think I am not creating either a string or an array correctly.

Here is a part of my sketch that deals with this issue:

Code: Select all

//Declaring variables.   
  int Hrs = now.hour();
  int Mins = now.minute();
  int Sec = now.second();

  int Time =(Hrs, Min, Sec);
 
  //This is just for debugging. Just to see what is being sent to the LED's
  Serial.println(Time);
  delay(1000);


Ok, at this point when I put all three values in "int Time" all I get is my seconds value printing out on the serial monitor and on my POV clock.

How can I get it to show all individual values. Keep in mind, I am only using the Serial.print command here JUST to see whats being sent to my POV display.

Thanks
Phillip B.
bafil
 
Posts: 9
Joined: Sun Apr 15, 2012 10:16 am

Re: String and Array Confusion

Postby pburgess » Wed Apr 25, 2012 4:55 pm

Greetings from one Phillip B. to another. :D

Problem is with these lines:
Code: Select all
  int Time =(Hrs, Min, Sec);
  Serial.println(Time);

The first line doesn't concatenate the values, nor are they being passed to a function. The syntax is still valid C though -- the comma operator normally lets you handle multiple assignments on one line (most frequently seen in the setup of 'for' loops)...but in this case, reduces to the equivalent of:
Code: Select all
  int Time = Sec;


To get these into a string (which is probably what you want), there are a couple of approaches...easiest is probably sprintf(), a la:
Code: Select all
  char Time[9];
  sprintf(Time, "%02:%02:%02", Hrs, Min, Sec);

The POV display code will then need to walk through the string, converting each ASCII character to your corresponding bitmap.
User avatar
pburgess
 
Posts: 1327
Joined: Sun Oct 26, 2008 1:29 am

Re: String and Array Confusion

Postby bafil » Wed Apr 25, 2012 5:30 pm

Hey Phillip B.

Thanks for the help but I still could not get what I needed.

I posted the entire code that I am using, so maybe it will be easier to understand. I had help with the code so there are still parts of it I am a bit confused about.

Code: Select all


Last edited by bafil on Mon Apr 30, 2012 9:28 am, edited 1 time in total.
bafil
 
Posts: 9
Joined: Sun Apr 15, 2012 10:16 am

Re: String and Array Confusion

Postby pburgess » Wed Apr 25, 2012 5:46 pm

You have both a local and a global variable named 'Time'. Inside the loop() function, don't declare the variable Time at all (so disregard that line in the code I previously posted)...remove the line, leave the global declaration at top, then sprintf() into the string as I showed. Should work at that point.
User avatar
pburgess
 
Posts: 1327
Joined: Sun Oct 26, 2008 1:29 am

Re: String and Array Confusion

Postby bafil » Mon Apr 30, 2012 9:30 am

Thanks for your help Phillip B.

I went through my code some more and did the changes you said and I finally got it to work.

Thanks again for your help
bafil
 
Posts: 9
Joined: Sun Apr 15, 2012 10:16 am


Return to General Project help

Who is online

Users browsing this forum: frontside180, Google [Bot] and 5 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [105]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]