Hi everyone. This is one that's stopped me cold. The code that I have here is for a POV clock using a ds1307 chip. No problems with getting Ard to talk to the ds1307 chip. I've used some code from another programmer (m. zoellner) that created a POV wand using 5 LEDs. My clock will have 8 LEDS and so I've created a set of arrays that graphically depict the numbers 0 - 9 on the top of the swing of the rotor and again another set of arrays that do the same for the bottom of the swing. You'll see these arrays at the top of the code. The arrays cannot be named by the number they represent however as this is not allowed in syntax of this coding. Thus I've had to represent them with a letter. Where the problem comes in is when I receive a number (you'll see in this current version of coding it's the seconds I'm trying to convert and display) from the ds1307 chip, I must change this numerical value to a letter value that will reference the corresponding array. This is done using two additional arrays called "stringaS" and "stringbS". This letter value then is sent into a function called either printNumTop or printNumBot. Well these functions do not like the char value that is being sent to them and I can't figure out how to get around this. I consistently get an error message that says "invalid conversion from char to int" when I try to compile the code.
.
Here's my code:
// POVNo!1
#include "Wire.h" // These declarations are for the DS1307 clock chip
#define DS1307_I2C_ADDRESS 0x68 // This is the I2C address
// These declarations are for the DS1307 clock chip
#define LEDIR 2 // Infared LED
// ******************* Top Number Arrays ********************************
int a_[] = {0,0,0,0,0,0,0,0, 0,0,1,0,0,1,0,0, 0,0,0,0,0,0,0,0}; // _
int a[] = {0,1,0,0,0,0,0,1, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,1}; // 1
int b[] = {0,1,0,0,1,1,1,1, 1,0,0,0,1,0,0,1, 0,1,1,1,1,0,0,1}; // 2 the actual digit graphic. These are given letter values because
int c[] = {0,1,0,0,1,0,1,0, 1,0,0,0,1,0,0,1, 0,1,1,1,1,1,1,0}; // 3 Arduino will not accept a number (ie "1", "2", etc) name in coding
int d[] = {1,1,1,1,0,0,0,0, 0,0,0,1,0,0,0,0, 1,1,1,1,1,1,1,1}; // 4
int e[] = {1,1,1,1,0,0,0,1, 1,0,0,1,0,0,0,1, 1,0,0,1,1,1,1,1}; // 5
int f[] = {0,1,1,1,1,1,1,0, 1,0,0,0,1,0,0,1, 0,1,0,0,0,1,1,0}; // 6 TOP OF CLOCK NUMBERS
int g[] = {1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0}; // 7
int h[] = {0,1,1,0,1,1,1,0, 1,0,0,1,0,0,0,1, 0,1,1,0,1,1,1,0}; // 8
int i[] = {0,1,1,1,1,1,1,0, 1,0,0,1,0,0,0,1, 0,1,1,0,0,0,1,0}; // 9
int j[] = {1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,1, 1,1,1,1,1,1,1,1}; // 0
// ************** Bottom Number Arrays *********************************
int l[] = {0,0,0,0,0,0,0,1, 1,1,1,1,1,1,1,1, 0,1,0,0,0,0,0,1}; // 1
int m[] = {0,1,1,1,1,0,0,1, 1,0,0,0,1,0,0,1, 0,1,0,0,1,1,1,1}; // 2
int n[] = {0,1,0,0,1,0,1,0, 1,0,0,0,1,0,0,1, 0,1,1,1,1,1,1,0}; // 3
int o[] = {1,1,1,1,0,0,0,0, 0,0,0,1,0,0,0,0, 1,1,1,1,1,1,1,1}; // 4 BOTTOM OF CLOCK NUMBERS
int p[] = {1,1,1,1,0,0,0,1, 1,0,0,1,0,0,0,1, 1,0,0,1,1,1,1,1}; // 5
int q[] = {0,1,1,1,1,1,1,0, 1,0,0,0,1,0,0,1, 0,1,0,0,0,1,1,0}; // 6
int r[] = {1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0}; // 7
int s[] = {0,1,1,0,1,1,1,0, 1,0,0,1,0,0,0,1, 0,1,1,0,1,1,1,0}; // 8
int t[] = {0,1,1,1,1,1,1,0, 1,0,0,1,0,0,0,1, 0,1,1,0,0,0,1,0}; // 9
int u[] = {1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,1, 1,1,1,1,1,1,1,1}; // 0
// *********************************************************************
// *************** Graphics Variables ********************************
int val = 0;
int numspace = 2;
int dottime =1;
char stringaS[11]={'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}; // Top of Clock array replacement values
char stringbS[11]={'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u'}; // Bottom of Clock array replacement values
// *************** Time Keeping Variables *****************************
int hour1, mins1, seconds, FirstDigSec, SecondDigSec, FirstDigMin, SecondDigMin, FirstDigHr, SecondDigHr;
byte second, minute, hour, second2;
// *********************************************************************
void setup() {
Wire.begin(); // To talk with the clock
Serial.begin(9600); // To talk with serial input/output
pinMode(5, OUTPUT); // These are the eight LED's on the rotor
pinMode(6, OUTPUT); //
pinMode(7, OUTPUT); //
pinMode(8, OUTPUT); //
pinMode(9, OUTPUT); //
pinMode(10, OUTPUT); //
pinMode(11, OUTPUT); //
pinMode(12, OUTPUT); //
pinMode(LEDIR, INPUT); // this is the Infrared sensor on the rotor
}
// ************************************ Decimal to Binary Conversion **********************************
byte decToBcd(byte val)
{
return ( (val/1016) + (val%10) );
}
// ************************************ Binary to Decimal Conversion **********************************
byte bcdToDec(byte val)
{
return ( (val/1610) + (val%16) );
}
// ********************************* Get the time from the DS1307 chip *******************************
void getTimeDs1307() { // Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0x00);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
second = bcdToDec(Wire.receive() & 0x7f);
// minute = bcdToDec(Wire.receive() & 0x8);
// second2 = bcdToDec(Wire.receive() & 0x8f);
// minute = bcdToDec(Wire.receive());
hour = bcdToDec(Wire.receive() & 0x3); // Need to change this if 12 hour am/pm
}
// *************************************** Top Number Display *******************************************
void printNumTop(int numbr[]) {
int y;
// printing the 1st row of the number
for (y = 0; y < 8; y++) {
//for (y = 7; y > 0; y--) {
digitalWrite(12 - y, numbr[y]);
}
delay(dottime);
// printing the 2nd row of the number
for (y = 0; y < 8; y++) {
digitalWrite(12 - y, numbr[y+8]);
}
delay(dottime);
// printing the 3rd row of the number
for (y = 0; y < 8; y++) {
digitalWrite(12 - y, numbr[y+16]);
}
delay(dottime);
for (y = 0; y < 8; y++) {
digitalWrite(y + 5, 0);
}
delay (numspace);
}
// ************************* Bottom Number Display *********************************************************
void printNumBot(int numbr[]) {
int y;
// printing the 1st row of the number
for (y = 0; y < 8; y++) {
digitalWrite(y + 5, numbr[y]);
}
delay(dottime);
// printing the 2nd row of the number
for (y = 0; y < 8; y++) {
digitalWrite(y + 5, numbr[y+8]);
}
delay(dottime);
// printing the 3rd row of the number
for (y = 0; y < 8; y++) {
digitalWrite(y + 5, numbr[y+16]);
}
delay(dottime);
for (y = 0; y < 8; y++) {
digitalWrite(y + 5, 0);
}
delay (numspace);
}
// ****************************************************************************************************************
void loop(){
getTimeDs1307(); // Get the current time
hour1 = hour;
mins1 = minute;
seconds = second;
SecondDigSec = second2;
if (seconds < 10 && seconds >= 0) { // These next 6 "if" statements create the 1st and 2nd digit values
FirstDigSec = 0; // of the seconds display.
SecondDigSec = (seconds - 0);
}
if (seconds < 20 && seconds >= 10) {
FirstDigSec = 1;
SecondDigSec = (seconds - 10);
}
if (seconds < 30 && seconds >= 20) {
FirstDigSec = 2;
SecondDigSec = (seconds - 20);
}
if (seconds < 40 && seconds >= 30) {
FirstDigSec = 3;
SecondDigSec = (seconds - 30);
}
if (seconds < 50 && seconds >= 40) {
FirstDigSec = 4;
SecondDigSec = (seconds - 40);
}
if (seconds < 60 && seconds >= 50) {
FirstDigSec = 5;
SecondDigSec = (seconds - 50);
}
// Serial.println(hour1); // only here for test purposes
// Serial.println(mins1); // only here for test purposes
// Serial.println(stringaS[SecondDigSec]); // only here for test purposes
// delay(500); // this line in particular must be commented out to work
val = digitalRead(LEDIR);
if (val == LOW){
printNumBot(stringbS[FirstDigSec]); // print the bottom numbers first becuase the IR sensor is at the 5 oclock position
printNumBot(stringbS[SecondDigSec]); // ditto
// delay(15);
// printNumTop(stringaS[FirstDigSec]); // now print the top numbers
// printNumTop(stringaS[SecondDigSec]); // ditto
}
}
// ************************* END *************************************************
A lenthy problem if you can understand my question. Run the code and you'll see what problem is arising here. Thanks for your input and help.
.
Tim