How to make arduino recognize a pair of numbers and turn on an led.
hello all, title may bit confusing have 2 numbers. rowstate ranges 1-5 , columnstate ranges 1-5. program first detects if "row button" hit. if 1 of 5 row buttons hit state of variable "rowstate" changes either 1-5 depedning on button hit. same columns. once hit row button , column button tell program print both of states see if works , does. question how light led 5 5 grid (max7219) using coordinates speak. if rowstate = 1 , columnstate = 1 , want have led (1,1) turn on. ideas, im still kind of beginner in arduino , i'm surprised got far project thankfull.
my code below if wondering.
my code below if wondering.
code: [select]
#define referencevoltage a0
#define buttonrow a1
#define buttoncolumn a2
#define ledb 2
#define ledc1 3
int voltage = analogread(referencevoltage);
int whichrow = analogread(buttonrow);
int rowstate = 0;
int columnstate = 0;
void setup()
{
serial.begin(9600);
}
void loop() {
while(rowstate == 0){
rowcheck();
}
while(columnstate == 0) {
columncheck();
}
serial.print("row =");
serial.println(rowstate);
serial.print("column =");
serial.println(columnstate);
delay(1000);
}
void rowcheck() {
int voltage = analogread(referencevoltage);
int whichrow = analogread(buttonrow);
if (whichrow > .9*voltage) {
serial.println("b");
rowstate = 1;
delay(250);
}
else {
if (whichrow > .7*voltage) {
serial.println("i");
rowstate = 2;
delay(250);
}
else {
if (whichrow > .5*voltage) {
serial.println("n");
rowstate = 3;
delay(250);
}
else {
if (whichrow > .3*voltage) {
serial.println("g");
rowstate = 4;
delay(250);
}
else {
if (whichrow > .1*voltage) {
serial.println("o");
rowstate = 5;
delay(250);
}
else {
serial.println("nothin hit");
delay(250);}
}
}
}
}
}
void columncheck() {
int voltage = analogread(referencevoltage);
int whichcolumn = analogread(buttoncolumn);
if (whichcolumn > .9*voltage) {
serial.println("1");
columnstate = 1;
delay(250);
}
else {
if (whichcolumn > .7*voltage) {
serial.println("2");
columnstate = 2;
delay(250);
}
else {
if (whichcolumn > .5*voltage) {
serial.println("3");
columnstate = 3;
delay(250);
}
else {
if (whichcolumn > .3*voltage) {
serial.println("4");
columnstate = 4;
delay(250);
}
else {
if (whichcolumn > .1*voltage) {
serial.println("5");
columnstate = 5;
delay(250);
}
else {
serial.println("nothin hit");
delay(250);}
}
}
}
}
}
ok, that's easy enough , there few ways it, common way use container "packet". want send data < value1 , value2 >. if first char '<', collect rest until serial monitor receives '>'. comma way split data multiple parts, need too.
so this.
i have working example if want take @ it.
so this.
quote
if(serial.available() > 0){
char temp = serial.read(); // example incomming data <1,23,456,7890>
if( temp == '<' ) // find char in buffer, , start collecting rest after it.
{
while( true ) // loop continuously gather rest of chars
// serial.available , serial.read() here.
//look @ incoming char , see if comma or end of container '>'
// if in not comma or >, store char(s) temporary array
// if char comma increment arrays index 1 store next char(s)
// keep doing until incoming char > break out of while loop , should have data
i have working example if want take @ it.
Arduino Forum > Using Arduino > Project Guidance > How to make arduino recognize a pair of numbers and turn on an led.
arduino
Comments
Post a Comment