I'm getting my first steps on Arduino and I'm trying to do an exercise where I have to draw a graph bar in a 16x2 LCD that indicates the values read from a vector of 16 integer elements amplified by the value read from a potentiometer (connected to the analog pin A0) during runtime. The graph should change in real-time as I move the cursor of the potentiometer to the left or right.
I have the following code structure:
void loop() {
// Read the 16 vector elements and map then to the screen height ...
// Print out their values multiplied by the value read form the potentiometer, to the serial monitor ...
// Draw a bar for each one of the vector elements (you will have 16 bars in the end)...
// If the graph has reached the screen edge do not amplify it anyfurther. If it has reached the bottom, do the same
//Wait a bit. Start drawing everything from scratch.
So far what I have is:
#include<LiquidCrystal.h>
// Create an LCD object and connect control wires
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int vector[16] = {3, 7, 10, 15, 28, 12, 43, 1, 6, 19, 29, 23, 54, 76, 57, 66};
int value=0;
void setup(){
Serial.begin(9600);
// Specify the LCD's number of columns and rows
lcd.begin(16, 2);
}
void loop(){
value = analogRead(A0);
for(int i=0; i<16; i++){
int vector2[i] = map(vector[i], 0, 1024, 0, 20);
Serial.println(vector2[i]*value);
}
}
However I'm getting the following error so far:
In function 'void loop()':
28:25: error: array must be initialized with a brace-enclosed initializer
exit status 1
Also I can't think of a way to do the last 3 steps of the code structure I have. I know that if i would want to print a bar like a character I could do:
#include<LiquidCrystal.h>
// Create an LCD object and connect control wires
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte bar[] ={B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111};
void setup(){
Serial.begin(9600);
// Specify the LCD's number of columns and rows
lcd.begin(16, 2);
lcd.createChar(0, bar);
}
void loop(){
lcd.setCursor(0,0);
cd.write(byte(0));
}
But even this would only print a column in the first row and column and not in both rows and first column of the LCD.
Can someone help me with the error I already have and give me some lights on how to do the last 3 steps of the code structure?
vector2[]
insideloop()
that has an undefined size because you did not properly declare it. The error is quite descriptive and will also highlight the line where the error was found.