Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Please help me with this code it's shows some error [but I can't be bothered to tell you what].

#include <TimerOne.h>

/**

 Analog Clock

 Paul Cox Dec 2010

*/

#define    PI       3.141592653589793e-06;

byte rows[8] = {9, 14, 8, 12, 1, 7, 2, 5};

byte cols[8] = {13, 3, 4, 10, 6, 11, 15, 16};

byte pins[16] = {5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};

byte screen[8] = {0, 0, 0, 0, 0, 0, 0, 0};

volatile byte screenRow = 0;

volatile byte screenCol = 0;

int iHour = 0;

int iMin = 0;

int iSec = 0;

void setup()

{

  Timer1.initialize(100);

  for (int i = 2; i <= 17; i++)

  {

     pinMode(i, OUTPUT);

  }

  Timer1.attachInterrupt(doubleBuffer);

  Serial.begin(9600);

  resetAnim();

}

void doubleBuffer()

{

  digitalWrite(translatePin(rows[screenRow]), LOW);

  digitalWrite(translatePin(cols[screenCol]), HIGH);

  screenCol++;

  if (screenCol >= 8)

  {

     screenCol = 0;

     screenRow++;

     if (screenRow >= 8)

     {

       screenRow = 0;

     }

   }

   if((screen[screenRow] >> screenCol) & B1 == B1)

   {

     digitalWrite(translatePin(rows[screenRow]), HIGH);

     digitalWrite(translatePin(cols[screenCol]), LOW);

   }

   else

   {

     digitalWrite(translatePin(rows[screenRow]), LOW);

     digitalWrite(translatePin(cols[screenCol]), HIGH);

   }

}

byte translatePin(byte original)

{

  return pins[original - 1];

}

void allOFF()

{

  for (int i = 0; i < 8; i++)

  {

     screen[i] = 0;

  }

}

void on(byte row, byte column)

{

  screen[column-1] |= (B1 << (row - 1));

}

void off(byte row, byte column)

{

  screen[column-1] &= ~(B1 << (row - 1));

}

void resetAnim()

{

  for (int i = 0; i < 8; i++)

  {

     screen[i] = B11111111;

     delay(25);

  }

  for (int i = 0; i < 8; i++)

  {

     screen[i] = B00000000;

     delay(25);

  }

}

void loop()

{

  drawClock();

  iSec++;

  if (iSec == 60)

  {

    iSec = 1;

    iMin++;

    if (iMin == 60)

    {

       iMin = 0;

       iHour++;

       if (iHour == 12)

       {

          iHour = 0;

       }

    }

  }

  delay(10);

}

void drawClock()

{

  allOFF();

  setHand(iHour,12,3);

  setHand(iMin,60,4);

  setHand(iSec,60,5);

}

// work out the pixel for a hand - val is out of a possible max val

// radius is distance from the centre

void setHand(int iVal, int iMax, int iRadius)

{

  double  dAngle = (iVal * 2 * PI) / iMax;

  double  dPosX = 4.5 + (iRadius * cos(dAngle));

  double  dPosY = 4.5 + (iRadius * sin(dAngle));

  drawLine(5,5,constrain(round(dPosX),1,8),constrain(round(dPosY),1,8));

}

void drawLine(int x0, int y0, int x1, int y1)

{

  int      iTemp;

  boolean  bSteep = abs(y1 - y0) > abs(x1 - x0);

  if (bSteep)

  {

     iTemp = x0; x0 = y0; y0 = iTemp;    // swap x0,y0

     iTemp = x1; x1 = y1; y1 = iTemp;    // swap x1,y1

  }

  if (x0 > x1)

  {

     iTemp = x0; x0 = x1; x1 = iTemp;    // swap x0,x1

     iTemp = y1; y1 = y0; y0 = iTemp;    // swap y0,y1

  }

  int deltax = x1 - x0;

  int deltay = abs(y1 - y0);

  int error = deltax / 2;

  int ystep = ((y0 < y1) ? 1 : -1);

  int y = y0;

  int x = x0;

  while(x <= x1)

  {
    if (bSteep)
    {
       on(y,x);
    }
    else
    {
       on(x,y);
    }
    error = error - deltay;
    if (error < 0)
    {
       y = y + ystep;
       error = error + deltax;
    }
    x++;
  }
}
share|improve this question
1  
What error does it show? And please format the code as a code block - highlight the code and press {} at the top of the editor. – Majenko Sep 14 '15 at 19:02
    
I#ll do it for you this once, but next time format your question properly. Also ask your question in the question area, not in the title! – Majenko Sep 14 '15 at 19:09
    
#define PI 3.141592653589793e-06; - apart from the semicolon problem, π is not 0.000003141592654. – Nick Gammon Sep 14 '15 at 20:47
1  
"it's shows some error [but I can't be bothered to tell you what]." I'm amazed anybody has bothered to tell you what the problem was. – CharlieHanson Sep 16 '15 at 14:59
    
A selfish can tell the comment like you my friend. all minds are not same. I SOLVED MY problem with other friend named Majenko. some people have good heart not like you . any way thank you very much. – shinas Sep 16 '15 at 18:49
up vote 2 down vote accepted

It's amazing the difference one character can make:

  • You must NEVER terminate a #define with a ; unless you absolutely know that you need one when it is expanded.

You have a macro defined:

#define    PI       3.141592653589793e-06;

That macro is then used here:

double  dAngle = (iVal * 2 * PI) / iMax;

Expand the macro PI and you get:

double  dAngle = (iVal * 2 * 3.141592653589793e-06;) / iMax;

Which obviously is a syntax error - you have a rogue ; in there where you really don't want one.

Oh, and one other thing - you shouldn't define PI - the Arudino core already defines it for you to a greater accuracy than you are:

arduino/Arduino.h:#define PI 3.1415926535897932384626433832795

... though you seem to be working in microPi's whatever those are...

share|improve this answer
1  
Maybe he's using an Arduino Micro? – Nick Gammon Sep 14 '15 at 20:45
    
@NickGammon Or he moves in MicroCircles.... – Majenko Sep 14 '15 at 20:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.