Hi all, I now have a problem trying to get my text to show the first character. For example, if i set the force as 100 it will only read 00. everything's working fine normally i would just put a space in front of my text however, i can't do it this time becsause i'm displaying a variable.
thanks
#include <Wire.h>
#define LCD05 0x63 // LCD05 address
char stringBuf[20];
char stringBuf1[4];
byte buffer[4];
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 11; // the number of the pushbutton pin
const int buttonPin2 = 10;
const int buttonPin3 = 9;
const int buttonPin4 = 8;
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int force = 100;
void setup() {
delay(100); // Delay to wait for everything to power up
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
Wire.begin();
buffer[0] = 0; // Clear the screen
buffer[1] = 12;
buffer[2] = 19;
buffer[3] = 31;
buffer[4] = 10;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();
}
void loop() {
while (buttonState1 == LOW){
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
if (buttonState3 == HIGH){
force = force +1;
}
if (buttonState4 == HIGH){
force = force -1;
}
// if (force <= 0){
// force = 0;
//}
/*
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 3;
buffer[4] = 1;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();
String message1 = " "; // The message to be put on the screen
int len1 = message1.length() + 1; // Length of the message
message1.toCharArray(stringBuf, len1); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len1);
Wire.endTransmission();
*/
Wire.begin();
buffer[0] = 0;
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 3;
buffer[4] = 15;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();
String displayforce = String(force); // The message to be put on the screen
int len2 = displayforce.length() + 1; // Length of the message
displayforce.toCharArray(stringBuf1, len2); // Convert the message to a car array
//itoa(force,stringBuf1,5);
// stringBuf1[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf1, len2);
Wire.endTransmission();
delay(150);
}
}
#include <Wire.h>
#define LCD05 0x63 // LCD05 address
char stringBuf[20];
char stringBuf1[4];
byte buffer[4];
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 11; // the number of the pushbutton pin
const int buttonPin2 = 10;
const int buttonPin3 = 9;
const int buttonPin4 = 8;
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int force = 100;
void setup() {
delay(100); // Delay to wait for everything to power up
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
Wire.begin();
buffer[0] = 12; // Clear the screen
buffer[1] = 19;
buffer[2] = 31;
buffer[3] = 10;
Wire.beginTransmission(LCD05);
Wire.write(buffer,4);
Wire.endTransmission();
}
void loop() {
while (buttonState1 == LOW){
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
if (buttonState3 == HIGH){
force = force +1;
}
if (buttonState4 == HIGH){
force = force -1;
}
// if (force <= 0){
// force = 0;
//}
/*
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 3;
buffer[4] = 1;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();
String message1 = " "; // The message to be put on the screen
int len1 = message1.length() + 1; // Length of the message
message1.toCharArray(stringBuf, len1); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len1);
Wire.endTransmission();
*/
Wire.begin();
buffer[0] = 19;
buffer[2] = 3;
buffer[3] = 3;
buffer[4] = 15;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();
String displayforce = String(force); // The message to be put on the screen
int len2 = displayforce.length() + 1; // Length of the message
displayforce.toCharArray(stringBuf1, len2); // Convert the message to a car array
//itoa(force,stringBuf1,5);
// stringBuf1[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf1, len2);
Wire.endTransmission();
delay(150);
}
while (buttonState1 == LOW){
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
Wire.begin();
buffer[0] = 19;
buffer[1] = 3;
buffer[2] = 3;
buffer[3] = 1;
Wire.beginTransmission(LCD05);
Wire.write(buffer,4);
Wire.endTransmission();
String message1 = " hi "; // The message to be put on the screen
int len1 = message1.length() + 1; // Length of the message
message1.toCharArray(stringBuf, len1); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len1);
Wire.endTransmission();
}
}
If I change byte buffer it either doesn't change at all or it stays the same same goes for all the other buffers if I change them starting from 0 instead of 1.
In your code. I don't know if that's your only problem but while there is an obvious thing that's wrong it doesn't make any sense to look elsewhere for problem.
A hint, print the space before you print the variable. If you are worried about buffer size add 1 to it but it appears you know about zero. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil
Hi all, I'm having trouble displaying my variable. Normally if I wanted to display a message all I would have to do is add a space in front then the message and then it reads fine. So what I'm trying to do is add a space before a variable so that when I want the variable "Force" to display 100 it doesn't just read 00 it will have the first character of 100.
How would I go about doing this without adding numbers in front because ill need to use the overall number later on to do some equations.
Normally, numeric variables don't have embedded spaces in them. Only when you come to print them in some way, do you start formatting them to display nicely.
Functions like snprintf() can be used for extensive formatting of numbers.
Maybe post the code you are having trouble with and say how the output should appear.