Thanks for the explanation Tony,
I implemented that in the code but seem to be getting similar errors:
invalid types 'char[byte {aka unsigned char}]' for array subscript
In line: data(buff[r]
);
of this sketch:
[code]
const byte inPin = A0; //Analog Sensor Input
int inValue; //Analog Sensor Value
char buff [13];
const byte COLUMN_N = 20; // Number of display columns
const byte ROW_N = 4; // Number of display rows
const byte SCLK = 13; // Arduino pin assigned to the SCLK line
const byte SDIN = 11; // Arduino pin assigned to the SID line
const byte TEXT[4][21] = {"1-Newhaven Display--",
"2-------Test--------",
"3-16/20-Characters--",
"4!@#$%^&*()_+{}[]<>?"}; // Strings to be displayed
byte new_line[4] = {0x80, 0xA0, 0xC0, 0xE0}; // DDRAM address for each line of the display (128, 160, 192, 224)
byte rows = 0x08; // Display mode: 2/4 lines; default (0x08 = 8)
void command(byte c) { // SUBROUTINE: PREPARES THE TRANSMISSION OF A COMMAND
byte i = 0; // Bit index
for(i=0; i<5; i++) {
digitalWrite(SDIN, HIGH);
clockCycle();
}
for(i=0; i<3; i++) {
digitalWrite(SDIN, LOW);
clockCycle();
}
send_byte(c); // Transmits the byte
}
void data(byte d) { // SUBROUTINE: PREPARES THE TRANSMISSION OF A BYTE OF DATA
byte i = 0; // Bit index
for(i=0; i<5; i++) {
digitalWrite(SDIN, HIGH);
clockCycle();
}
digitalWrite(SDIN, LOW);
clockCycle();
digitalWrite(SDIN, HIGH);
clockCycle();
digitalWrite(SDIN, LOW);
clockCycle();
send_byte(d); // Transmits the byte
}
void send_byte(byte tx_b) { // SUBROUTINE: SEND TO THE DISPLAY THE BYTE IN tx_b
byte i = 0; // Bit index
for(i=0; i<4; i++) {
if((tx_b & 0x01) == 1) {
digitalWrite(SDIN, HIGH);
}
else {
digitalWrite(SDIN, LOW);
}
clockCycle();
tx_b = tx_b >> 1;
}
for(i=0; i<4; i++) {
digitalWrite(SDIN, LOW);
clockCycle();
}
for(i=0; i<4; i++) {
if((tx_b & 0x1) == 0x1) { // <------- Change (?)
digitalWrite(SDIN, HIGH);
}
else {
digitalWrite(SDIN, LOW);
}
clockCycle();
tx_b = tx_b >> 1;
}
for(i=0; i<4; i++) {
digitalWrite(SDIN, LOW);
clockCycle();
} }
void clockCycle(void) { // SUBROUTINE: EXECUTE THE CLOCK SIGNAL CYCLE
//digitalWrite(CS, LOW); // Sets LOW the /CS line of the display (optional, can be always low)
// delayMicroseconds(1);
digitalWrite(SCLK, LOW); // Sets LOW the SCLK line of the display
delayMicroseconds(1);
digitalWrite(SCLK, HIGH); // Sets HIGH the SCLK line of the display
delayMicroseconds(1);
//digitalWrite(CS, HIGH); // Sets HIGH the /CS line of the display (optional, can be always low)
// delayMicroseconds(1);
}
void output(void) { // SUBROUTINE: DISPLAYS THE FOUR STRINGS, THEN THE SAME IN REVERSE ORDER
inValue = analogRead(inPin);
snprintf (buff, 13, "Value = %d", inValue );
byte r = 0; // Row index
byte c = 0; // Column index
command(0x01); // Clears display (and cursor home)
delay(2); // After a clear display, a minimum pause of 1-2 ms is required
for (r=0; r<ROW_N; r++) { // One row at a time
command(new_line[r]); // Moves the cursor to the first column of that line
for (c=0; c<COLUMN_N; c++) { // One character at a time
data(buff[r][c]); // Displays the corresponding string
} } }
void setup(void) {
pinMode(SCLK, OUTPUT); // Initializes Arduino pin for the SPI Clock line
digitalWrite(SCLK, HIGH); // Sets HIGH the SPI Clock line of the display
pinMode(SDIN, OUTPUT); // Initializes Arduino pin for the SPI MOSI line
digitalWrite(SDIN, LOW); // Sets LOW the SPI MOSI line of the display
//pinMode(SDOUT, INPUT); // Initializes Arduino pin for the SPI MISO line (optional, can be not connected)
//pinMode(CS, OUTPUT); // Initializes Arduino pin for the SPI Chip Select line (optional - for multiple slaves)
//digitalWrite(CS, HIGH); // Sets HIGH the SPI Chip Select line of the display (optional, can be always low)
//pinMode(RES, OUTPUT); // Initializes Arduino pin for the Reset line (optional)
//digitalWrite(RES, HIGH); // Sets HIGH the Reset line of the display (optional, can be always high)
delayMicroseconds(200);
command(0x22 | rows); // Function set: extended command set (RE=1), lines # (0x22 = 34)
command(0x71); // Function selection A: (0x71 = 113)
data(0x5C); // Enable internal Vdd regulator at 5V I/O mode (default) (0x00 for disable: 2.8V I/O) (0x5C = 92)
command(0x20 | rows); // Function set: fundamental command set (RE=0) (exit from extended command set), lines # (0x20 = 32)
command(0x08); // Display ON/OFF control: display off, cursor off, blink off (default values) (0x08 = 8)
command(0x22 | rows); // Function set: extended command set (RE=1), lines # (0x22 = 34)
command(0x79); // OLED characterization: OLED command set enabled (SD=1) (0x79 = 121)
command(0xD5); // Set display clock divide ratio/oscillator frequency: (0xD5 = 213)
command(0x70); // Divide ratio=1, frequency=7 (default values) (0x70 = 112)
command(0x78); // OLED characterization: OLED command set disabled (SD=0) (exit from OLED command set) (0x78 = 120)
command(0x09); // Extended function set (RE=1): 5-dot font, B/W inverting disabled (def. val.), 3/4 lines (0x09 = 9)
command(0x06); // Entry Mode set - COM/SEG direction: COM0->COM31, SEG99->SEG0 (BDC=1, BDS=0) (0x06 = 6)
command(0x72); // Function selection B: (0x72 = 114)
data(0x0A); // ROM/CGRAM selection: ROM C, CGROM=250, CGRAM=6 (ROM=10, OPR=10) (0x0A = 10)
command(0x79); // OLED characterization: OLED command set enabled (SD=1) (0x79 = 121)
command(0xDA); // Set SEG pins hardware configuration: (0xDA = 218)
command(0x10); // Alternative odd/even SEG pin, disable SEG left/right remap (default values) (0x10 = 16)
command(0xDC); // Function selection C: (0xDC = 220)
command(0x00); // Internal VSL, GPIO input disable (0x00 = 0)
command(0x81); // Set contrast control: (0x81 = 129)
command(0x7F); // Contrast=127 (default value) (0x7F = 127)
command(0xD9); // Set phase length: (0xD9 = 217)
command(0xF1); // Phase2=15, phase1=1 (default: 0x78) (0x78 = 120)
command(0xDB); // Set VCOMH deselect level: (0xDB = 219)
command(0x40); // VCOMH deselect level=1 x Vcc (default: 0x20=0,77 x Vcc) (0x40 = 64)
command(0x78); // OLED characterization: OLED command set disabled (SD=0) (exit from OLED command set) (0x78 = 120)
command(0x20 | rows); // Function set: fundamental command set (RE=0) (exit from extended command set), lines # (0x20 = 32)
command(0x01); // Clear display (0x01 = 1)
delay(2);
command(0x80); // Set DDRAM address 0x00 in address counter (cursor home) (default value) (0x80 = 128)
command(0x0C); // Display ON/OFF control: display ON, cursor off, blink off (0x0C = 12)
delay(250);
}
void loop(void) {
output(); // Execute subroutine "output"
delay(2000);
}
[/code]
Or if I exclude the [r][c] to leave: data(buff); // Displays the corresponding string
it compiles okay but I get a flickery LCD screen of eighty letter "d"'s.