Hi possibly a very noobish question so apologies.
I am making a simple program to teach myself how pointers work.
Basically, I have tried to write a program that turns on LED1 on its first loop through, then turn on LED2 on its second loop through etc using pointers.
I have written the code with the understanding that where ever I put the pointer, the program will substitute it for the variable it is currently pointing to/associated with.
int Count = 1; //a variable which increments every loop of the program
int *pointer1; //pointer which points to LED outputs
int *pointer2; //pointer which points to LED target
int LedState1 = LOW; //LED output logic level 1
int LedState2 = LOW; //LED output logic level 2
int LedState3 = LOW; //LED output logic level 3
int Led1 = 5; //Pin# with LED 1 on
int Led2 = 8; //Pin# with LED 1 on
int Led3 = 9; //Pin# with LED 1 on
void setup() {
Serial.begin(9600);
pinMode(Led1,OUTPUT);
pinMode(Led2,OUTPUT);
pinMode(Led3,OUTPUT);
}
void loop() {
if (Count == 1)
{
pointer1 = &LedState1; //so in digitalwrite at end of loop, the second half will be LedState1
pointer2 = &Led1; //first half of digitalwrite will be Led1
}
if (Count == 2)
{
pointer1 = &LedState2; //second half will be substitued for LedState2
pointer2 = &Led1; //first half of digitalwrite will be Led2
}
if (Count == 3)
{
pointer1 = &LedState3; //second half will be substitued for LedState3
pointer2 = &Led1; //first half of digitalwrite will be Led3
}
if (pointer1 == HIGH) //changing LedStateN logic levels
{
pointer1 = LOW;
}
else
{
pointer1 = HIGH;
}
digitalWrite(pointer2, pointer1)
if (Count < 3) ++Count;
else
{
Count = 1;
}
}
With this code, I get the error message_invalid conversion from ‘int’ to ‘int*’ [-fpermissive]_ on the line “pointer1 = HIGH”.
I would have thought this would have worked, because if variable Count = 1 > then pointer1 points to variable LedState1 > then that line which is has been highlighted as wrong would read LedState1 = HIGH… which makes sense? Where am I going wrong?