- #1
creativen
- 22
- 0
I'm newbie in C programming...
i'm trying to make my arduino board works but still find error when compiling the C programming, the errors are:
driving7segmentusingmultipleshiftregisters3:2: error: expected constructor, destructor, or type conversion before ';' token
driving7segmentusingmultipleshiftregisters3:85: error: ISO C++ forbids declaration of 'sendSerialDatainitial' with no type
driving7segmentusingmultipleshiftregisters3.cpp: In function 'int sendSerialDatainitial()':
driving7segmentusingmultipleshiftregisters3:95: error: assignment of read-only variable 'g_pinCommLatch1'
driving7segmentusingmultipleshiftregisters3:96: error: expected `;' before 'g_pinCommLatch2'
driving7segmentusingmultipleshiftregisters3:99: error: expected `;' before ')' token
driving7segmentusingmultipleshiftregisters:127: error: expected `}' at end of input
i'm trying to make my arduino board works but still find error when compiling the C programming, the errors are:
driving7segmentusingmultipleshiftregisters3:2: error: expected constructor, destructor, or type conversion before ';' token
driving7segmentusingmultipleshiftregisters3:85: error: ISO C++ forbids declaration of 'sendSerialDatainitial' with no type
driving7segmentusingmultipleshiftregisters3.cpp: In function 'int sendSerialDatainitial()':
driving7segmentusingmultipleshiftregisters3:95: error: assignment of read-only variable 'g_pinCommLatch1'
driving7segmentusingmultipleshiftregisters3:96: error: expected `;' before 'g_pinCommLatch2'
driving7segmentusingmultipleshiftregisters3:99: error: expected `;' before ')' token
driving7segmentusingmultipleshiftregisters:127: error: expected `}' at end of input
Code:
sendSerialDataInitial (void);
void setup();
int switchPin1 = A0;
int switchPin2 = A2;
int switchPin3 = A4;
int resetPin1 = A1;
int resetPin2 = A3;
int resetPin3 = A5;
int no1=1;
int no2=1;
int no3=1;
// This pin gets sets low when I want the 595s to listen
const int g_pinCommLatch1 = 5;
const int g_pinCommLatch2 = 6;
const int g_pinCommLatch3 = 7;
// This pin is used to pass the next bit
const int g_pinData1 = 8;
const int g_pinData2 = 9;
const int g_pinData3 = 10;
// This pin is used by ShiftOut to toggle to say there's another bit to shift
const int g_pinClock1 = 11;
const int g_pinClock2 = 12;
const int g_pinClock3 = 13;
// Definitions of the 7-bit values for displaying digits
byte g_digits [10];
// Current number being displayed
int g_numberToDisplay1 = 0;
int g_numberToDisplay2 = 0;
int g_numberToDisplay3 = 0;
// Number of shift registers in use
const int g_registers = 5;
// Array of numbers to pass to shift registers
byte g_registerArray [g_registers];
byte *pValueArray1;
byte *pValueArray2;
byte *pValueArray3;
byte reg1;
byte reg2;
byte reg3;
byte value1;
byte value2;
byte value3;
byte bitMask1;
byte bitMask2;
byte bitMask3;
void setup()
{
pinMode (g_pinCommLatch1, OUTPUT);
pinMode (g_pinCommLatch2, OUTPUT);
pinMode (g_pinCommLatch3, OUTPUT);
pinMode (g_pinClock1, OUTPUT);
pinMode (g_pinClock2, OUTPUT);
pinMode (g_pinClock3, OUTPUT);
pinMode (g_pinData1, OUTPUT);
pinMode (g_pinData2, OUTPUT);
pinMode (g_pinData3, OUTPUT);
// Setup the digits array
g_digits [0] = 1 + 2 + 4 + 8 + 16 + 32 + 00;
g_digits [1] = 0 + 2 + 4 + 0 + 00 + 00 + 00;
g_digits [2] = 1 + 2 + 0 + 8 + 16 + 00 + 64;
g_digits [3] = 1 + 2 + 4 + 8 + 00 + 00 + 64;
g_digits [4] = 0 + 2 + 4 + 0 + 00 + 32 + 64;
g_digits [5] = 1 + 0 + 4 + 8 + 00 + 32 + 64;
g_digits [6] = 1 + 0 + 4 + 8 + 16 + 32 + 64;
g_digits [7] = 1 + 2 + 4 + 0 + 00 + 00 + 00;
g_digits [8] = 1 + 2 + 4 + 8 + 16 + 32 + 64;
g_digits [9] = 1 + 2 + 4 + 8 + 00 + 32 + 64;
}
sendSerialDatainitial(void)
{ g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [0] = g_digits [0];
// Signal to the 595s to listen for data
digitalWrite (g_pinCommLatch1,LOW);
g_pinCommLatch1=LOW
g_pinCommLatch2=LOW
g_pinCommLatch3=LOW
for (reg1 = registerCount1; reg1 > 0; reg1--)
{
byte value1 = pValueArray1 [reg1-1];
for (byte bitMask1 = 128; bitMask1 > 0; bitMask1 >>= 1)
{
digitalWrite (g_pinClock1, LOW);
digitalWrite (g_pinData1, value1 & bitMask1 ? HIGH : LOW);
digitalWrite (g_pinClock1, HIGH);
}
}
for (byte reg2 = registerCount2; reg2 > 0; reg2--)
{
byte value2 = pValueArray2 [reg2-1];
for (byte bitMask2 = 128; bitMask2 > 0; bitMask2 >>= 1)
{
digitalWrite (g_pinClock2, LOW);
digitalWrite (g_pinData2, value2 & bitMask2 ? HIGH : LOW);
digitalWrite (g_pinClock2, HIGH);
}
}
for (byte reg3 = registerCount3; reg3 > 0; reg3--)
{
byte value3 = pValueArray3 [reg3-1];
for (byte bitMask3 = 128; bitMask3 > 0; bitMask3 >>= 1)
{
digitalWrite (g_pinClock3, LOW);
digitalWrite (g_pinData3, value3 & bitMask3 ? HIGH : LOW);
digitalWrite (g_pinClock3, HIGH);
}
}
// Signal to the 595s that I'm done sending
digitalWrite (g_pinCommLatch1, HIGH);
digitalWrite (g_pinCommLatch2, HIGH);
digitalWrite (g_pinCommLatch3, HIGH);
}
Tombol:
GoSub Blinks
if switchPin1=1 and a=1 then
GoSub Counter1
a=0
elseif switchPin1=0 and a=0 then
a=1
end if
if switchPin2=1 and b=1 then
GoSub Counter2
b=0
elseif switchPin2=0 and b=0 then
b=1
end if
if switchPin3=1 and c=1 then
GoSub Counter3
c=0
elseif switchPin3=0 and c=0 then
c=1
end if
if resetPin1=1 and a=1 then
GoSub reset1
end if
if resetPin2=1 and a=1 then
GoSub reset2
end if
if resetPin3=1 and a=1 then
GoSub reset3
end if
GoSub Show1
GoSub Show2
GoSub Show3
GoSub SendSerialData1
GoSub SendSerialData2
GoSub SendSerialData3
delay(1000
GoSub Tombol
Blinks:
int a = random (1,3);
int b = random (1,4);
int c = random (1,5);
if (a==3)
digitalWrite(2, HIGH); // set the LED on
end if
if (b==3)
digitalWrite(3, HIGH); // set the LED on
end if
if (c==3)
digitalWrite(3, HIGH); // set the LED on
end if
return
Counter1:
g_numberToDisplay1 = no1;
no1=no1+1;
return
Counter2:
g_numberToDisplay2 = no2;
no2=no2+1;
return
Counter3:
g_numberToDisplay3 = no3;
no3=no3+1;
return
Reset1:
gnumberToDisplay1 = no1;
no1=0
return
Reset2:
gnumberToDisplay2 = no2;
no2=0
return
Reset3:
gnumberToDisplay3 = no3;
no3=0
return
show1:
if (g_numberToDisplay1 < 10)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [0] = g_digits [g_numberToDisplay1];
}
else if (g_numberToDisplay1 < 100)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [1] = g_digits [g_numberToDisplay1 / 10];
g_registerArray [0] = g_digits [g_numberToDisplay1 % 10];
}
else if (g_numberToDisplay1 < 1000)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [g_numberToDisplay1 / 100];
g_registerArray [1] = g_digits [(g_numberToDisplay1 % 100) / 10];
g_registerArray [0] = g_digits [g_numberToDisplay1 % 10];
}
else if (g_numberToDisplay1 < 10000)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [g_numberToDisplay1 / 1000];
g_registerArray [2] = g_digits [(g_numberToDisplay1 % 1000) / 100];
g_registerArray [1] = g_digits [(g_numberToDisplay1 % 100) / 10];
g_registerArray [0] = g_digits [g_numberToDisplay1 % 10];
}
else
{
g_registerArray [4] = g_digits [g_numberToDisplay1 / 10000];
g_registerArray [3] = g_digits [(g_numberToDisplay1 % 10000) / 1000];
g_registerArray [2] = g_digits [(g_numberToDisplay1 % 1000) / 100];
g_registerArray [1] = g_digits [(g_numberToDisplay1 % 100) / 10];
g_registerArray [0] = g_digits [g_numberToDisplay1 % 10];
}
return
show2:
if (g_numberToDisplay2 < 10)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [0] = g_digits [g_numberToDisplay2];
}
else if (g_numberToDisplay2 < 100)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [1] = g_digits [g_numberToDisplay2 / 10];
g_registerArray [0] = g_digits [g_numberToDisplay2 % 10];
}
else if (g_numberToDisplay2 < 1000)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [g_numberToDisplay2 / 100];
g_registerArray [1] = g_digits [(g_numberToDisplay2 % 100) / 10];
g_registerArray [0] = g_digits [g_numberToDisplay2 % 10];
}
else if (g_numberToDisplay2 < 10000)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [g_numberToDisplay2 / 1000];
g_registerArray [2] = g_digits [(g_numberToDisplay2 % 1000) / 100];
g_registerArray [1] = g_digits [(g_numberToDisplay2 % 100) / 10];
g_registerArray [0] = g_digits [g_numberToDisplay2 % 10];
}
else
{
g_registerArray [4] = g_digits [g_numberToDisplay2 / 10000];
g_registerArray [3] = g_digits [(g_numberToDisplay2 % 10000) / 1000];
g_registerArray [2] = g_digits [(g_numberToDisplay2 % 1000) / 100];
g_registerArray [1] = g_digits [(g_numberToDisplay2 % 100) / 10];
g_registerArray [0] = g_digits [g_numberToDisplay2 % 10];
}
return
show3:
if (g_numberToDisplay3 < 10)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [0] = g_digits [g_numberToDisplay3];
}
else if (g_numberToDisplay3 < 100)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [1] = g_digits [g_numberToDisplay3 / 10];
g_registerArray [0] = g_digits [g_numberToDisplay3 % 10];
}
else if (g_numberToDisplay3 < 1000)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [0];
g_registerArray [2] = g_digits [g_numberToDisplay3 / 100];
g_registerArray [1] = g_digits [(g_numberToDisplay3 % 100) / 10];
g_registerArray [0] = g_digits [g_numberToDisplay3 % 10];
}
else if (g_numberToDisplay3 < 10000)
{
g_registerArray [4] = g_digits [0];
g_registerArray [3] = g_digits [g_numberToDisplay3 / 1000];
g_registerArray [2] = g_digits [(g_numberToDisplay3 % 1000) / 100];
g_registerArray [1] = g_digits [(g_numberToDisplay3 % 100) / 10];
g_registerArray [0] = g_digits [g_numberToDisplay3 % 10];
}
else
{
g_registerArray [4] = g_digits [g_numberToDisplay3 / 10000];
g_registerArray [3] = g_digits [(g_numberToDisplay3 % 10000) / 1000];
g_registerArray [2] = g_digits [(g_numberToDisplay3 % 1000) / 100];
g_registerArray [1] = g_digits [(g_numberToDisplay3 % 100) / 10];
g_registerArray [0] = g_digits [g_numberToDisplay3 % 10];
}
return
sendSerialData1:
// Signal to the 595s to listen for data
digitalWrite (g_pinCommLatch1, LOW);
for (byte reg1 = registerCount1; reg1 > 0; reg1--)
{
byte value1 = pValueArray1 [reg1 - 1];
for (byte bitMask1 = 128; bitMask1 > 0; bitMask1 >>= 1)
{
digitalWrite (g_pinClock1, LOW);
digitalWrite (g_pinData1, value1 & bitMask1 ? HIGH : LOW);
digitalWrite (g_pinClock1, HIGH);
}
}
// Signal to the 595s that I'm done sending
digitalWrite (g_pinCommLatch1, HIGH);
return
sendSerialData2:
// Signal to the 595s to listen for data
digitalWrite (g_pinCommLatch2, LOW);
for (byte reg2 = registerCount2; reg2 > 0; reg2--)
{
byte value2 = pValueArray2 [reg2 - 1];
for (byte bitMask2 = 128; bitMask2 > 0; bitMask2 >>= 1)
{
digitalWrite (g_pinClock2, LOW);
digitalWrite (g_pinData2, value2 & bitMask2 ? HIGH : LOW);
digitalWrite (g_pinClock2, HIGH);
}
}
// Signal to the 595s that I'm done sending
digitalWrite (g_pinCommLatch2, HIGH);
return
sendSerialData3:
// Signal to the 595s to listen for data
digitalWrite (g_pinCommLatch3, LOW);
for (byte reg3 = registerCount3; reg3 > 0; reg3--)
{
byte value3 = pValueArray3 [reg3 - 1];
for (byte bitMask3 = 128; bitMask3 > 0; bitMask3 >>= 1)
{
digitalWrite (g_pinClock3, LOW);
digitalWrite (g_pinData3, value3 & bitMask3 ? HIGH : LOW);
digitalWrite (g_pinClock3, HIGH);
}
}
// Signal to the 595s that I'm done sending
digitalWrite (g_pinCommLatch3, HIGH);
return