Go Down

Topic: Need help LCD display problems (Read 546 times) previous topic - next topic

fenixc94

Nov 23, 2016, 04:39 pm Last Edit: Nov 23, 2016, 04:58 pm by CrossRoads
Hey folks,

So I am 90% finished this college project I have to do and the last part is LCD display related. This is the code below
Code: [Select]
#include <Wire.h> //Import wire library

#include "rgb_lcd.h" //Import Grove LCD Library

////////////////////////////////////////GLOBAL VARIABLES//////////////////////////////////////


rgb_lcd lcd;
int sum, average;
int voteOpinion;
int MY_ADDRESS = 10; //Update for board number
int dataArray[6];
int counter = 0;
int currentQuestion = 30;
int newDataArray[6];

int delayTime = 1000;

int agreeDisagree;
int ArrayNum;
int deciding = 20;

////////////////////////////////////SETUP///////////////////////////////////////////////////
void setup()
{  
  
    Wire.begin(MY_ADDRESS);     //Set address of this board for the I2C bus
    Serial.begin(57600); //open serial port with baud rate 9600 , must match serial monitor baud rate for sampling!!
    lcd.begin(16,2); //Initialize LCD interface and specify the dimensions of the display
}

///////////////////////////////////////LOOP////////////////////////////////////////////////

void loop()
{
 arrayData();
 deciderFunction();
 delay(1000); //Pause the program for 1000 miliseconds
}

////////////////////////////////////BUILD ARRAY////////////////////////////////////////////

void arrayData()
{
  //slave adresses go from 11 to 16 inclusive
 for(int i = 11; i < 16; i++)
   {
   Wire.requestFrom(i, 1); //request data from a slave device.
   while (Wire.available()) //return data
      {
      ArrayNum = Wire.read(); //read data that was transmitted from slave device
      dataArray[i-11] = ArrayNum;
      counter++;
      }
   }

  for(int i = 0; i < 6; i++)
    {
      Serial.print(dataArray[i]); //print data to the serial port as ASCII text
      Serial.print(" ");
    }
  
  Serial.println(" ");
}

///////////////////////////////DETERMINE VALUES TO SEND/////////////////////////////////////////
void deciderFunction(){
   //count a number of times before switching to request that the arduino slaves vote
   if(deciding <= 30){
    voteOpinion = 20;
    Serial.println("I'm in here!");
    deciding++;
   }

   else if(deciding == 31){
    voteOpinion = 21;
    deciding++;
    Serial.println("but now i'm here askjdhjkabsf");
    
   }

   //tell slaves to cast vote
   else if(deciding == 32){
    Serial.println("Now I'm in HERE!");
  
    voteOpinion = 22;

    //cycle through questions each time slaves are done voting
    if(currentQuestion < 34){
      currentQuestion++;
    }
    else if(currentQuestion == 34){
      currentQuestion = 30;
    }
    deciding = 20;
    
   }
   
 //get average of votes and send back 40 (agree) or 41 (disagree)
    for(int w = 0; w < 5; w++)
        {
          sum += dataArray[w];
        }
        
        average = sum/5;
        if(average <= 5)
        {
          agreeDisagree = 40;
        }
        
        else if(average > 5)
         {
            agreeDisagree = 41;
         }
       int slaveAddress;


  //send to all slave addresses 11 - 16    
     for(int i = 11; i < 16; i++)
      {
         slaveAddress = i;
      }
  //send essential data to function to transmit numbers to slave
  transmitData(slaveAddress, currentQuestion, voteOpinion, agreeDisagree);
  lcdDisplay(currentQuestion);
}

/////////////////////////////SEND DATA TO SLAVE/////////////////////////////////////////////////

void transmitData(int slaveAddress, int question, int voteOpinion, int finalVote){

   Wire.beginTransmission(slaveAddress); //begin transmission to I2C slave device with the given address.
  
   //queue data for transmission from the master to the slave device
   Wire.write(question); //first data
   Wire.write(voteOpinion); //second data
   for(int i = 0; i < 6; i++)
    {      
      Wire.write(dataArray[i]); //third data
    }
    //if opinion reaches vote, send the average
   if(voteOpinion == 22){
      Wire.write(finalVote);//four data
   }
  
   Wire.endTransmission(slaveAddress); //end transmission to slave device and transmit data
}

///////////////////////////LCD DISPLAY////////////////////////////////

void lcdDisplay(int question){
  if(question = 30){
    lcd.setCursor(1,0); //set the location of the text that will be displayed on the LCD
    lcd.print("question 30!"); //print text to LCD
    
  }
  else if(question = 31){
    lcd.setCursor(1,0);
    lcd.print("question 31!");
  }
  else if(question = 32){
    lcd.setCursor(1,0);
    lcd.print("question 32!");
  }
  else if(question = 33){
    lcd.setCursor(1,0);
    lcd.print("question 33!");
  }
  else if(question = 34){
    lcd.setCursor(1,0);
    lcd.print("question 34!");
  }
}


Essentially I am having problems getting the code at the end (LCD Display section) to go through all of the questions. All that comes up on the display screen is "question 30!". It's probably a simple solution but I am racking my brain trying to figure it out. Any suggestions would be greatly appreciated. Thanks and peace

CrossRoads

#1
Nov 23, 2016, 04:54 pm Last Edit: Nov 23, 2016, 04:59 pm by CrossRoads
So now the 90/10 rule kicks in: 90% of the work takes 10% of the time, and the remaining 10% of the work takes 90% of time 8)
I fixed your post with code tags.

These lines
if(question = 30){
assign a value. You need == to compare the value.

Fix those, maybe the 10% won't take the full 90% of time.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

fenixc94

Thanks so much man. I knew it was gonna be something so simple. But thanks nonetheless ;)

jimLee

Jim's law : No project can be more than 50% complete, until its complete.

-jim lee
PNW Ardiuno & Maker club
1012 9Th Street, Anacortes, WA 98221 (Around the back of building)
Contact jimLee or Naneen for more info

Go Up