Specifying the '1's place
setup - lcd 1602 character display hooked arduino. arduino running basic color changing rgb led varying r, g, , b outputs (0-255).
lcd displays "red: blue: "
green: "
and supposed show values each (i.e. "red:255 blue:0 green:255"
the problem have initial value 255. counts down, when gets below 100, ones , tens place shifts left, leaving tailing zero. when initial value 0, counts through 255, ones place gets shifted right @ 10 , again @ 100.
i display show values '1's place locked in specific spot , removing leading zeros.
also, in code, have print function within each 255 - 0 transition, make subroutine that's called in each location , many lines of setting cursors , words done once.
thanks can offer!
lcd displays "red: blue: "
green: "
and supposed show values each (i.e. "red:255 blue:0 green:255"
the problem have initial value 255. counts down, when gets below 100, ones , tens place shifts left, leaving tailing zero. when initial value 0, counts through 255, ones place gets shifted right @ 10 , again @ 100.
i display show values '1's place locked in specific spot , removing leading zeros.
also, in code, have print function within each 255 - 0 transition, make subroutine that's called in each location , many lines of setting cursors , words done once.
thanks can offer!
code: [select]
#define green 6
#define blue 11
#define red 10
#define delaytime 20
#include <liquidcrystal.h>
liquidcrystal lcd(7, 8, 9, 5, 4, 12);
void setup() {
pinmode(green, output);
pinmode(blue, output);
pinmode(red, output);
digitalwrite(green, high);
digitalwrite(blue, high);
digitalwrite(red, high);
lcd.begin(16,2);
}
int redval;
int blueval;
int greenval;
void loop() {
int redval = 255;
int blueval = 0;
int greenval = 0;
for( int = 0 ; < 255 ; += 1 ){
greenval += 1;
redval -= 1;
analogwrite( green, greenval );
analogwrite( red, redval );
lcd.setcursor(0,0);
lcd.print("red:");
lcd.setcursor(4,0);
lcd.print(redval);
lcd.setcursor(8,0);
lcd.print("blue:");
lcd.setcursor(12,0);
lcd.print(blueval);
lcd.setcursor(0,1);
lcd.print("green:");
lcd.setcursor(8,1);
lcd.print(greenval);
delay( delaytime );
}
lcd.clear();
redval = 0;
blueval = 0;
greenval = 255;
for( int = 0 ; < 255 ; += 1 ){
blueval += 1;
greenval -= 1;
analogwrite( blue, blueval );
analogwrite( green, greenval );
lcd.setcursor(0,0);
lcd.print("red:");
lcd.setcursor(4,0);
lcd.print(redval);
lcd.setcursor(8,0);
lcd.print("blue:");
lcd.setcursor(12,0);
lcd.print(blueval);
lcd.setcursor(0,1);
lcd.print("green:");
lcd.setcursor(8,1);
lcd.print(greenval);
delay( delaytime );
}
lcd.clear();
redval = 0;
blueval = 255;
greenval = 0;
for( int = 0 ; < 255 ; += 1 ){
redval += 1;
blueval -= 1;
analogwrite( red, redval );
analogwrite( blue, blueval );
lcd.setcursor(0,0);
lcd.print("red:");
lcd.setcursor(4,0);
lcd.print(redval);
lcd.setcursor(8,0);
lcd.print("blue:");
lcd.setcursor(12,0);
lcd.print(blueval);
lcd.setcursor(0,1);
lcd.print("green:");
lcd.setcursor(8,1);
lcd.print(greenval);
delay( delaytime );
}
}
use sprintf field width specifier, or print space after number print
code: [select]
char buffer [5];
sprintf (buffer, "%4d", redval);
lcd.print(buffer);
Arduino Forum > Using Arduino > Displays > Specifying the '1's place
arduino
Comments
Post a Comment