Our Code

This is our Check Yo Self Code.


/*Check Yo Self
Claire Shorall, Ronye Cooper, Laura Hernandez, 
Saundrea McElroy, and Sandra Vivian

9/27-28, 2014

 */

// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// set up a constant for the tilt switchPin
const int switchPin = 6;

// variable to hold the value of the switchPin
int switchState = 0;

// variable to hold previous value of the switchpin
int prevSwitchState = 0;

// a variable to choose which reply from the crystal ball
int reply=-1;

const int inPin = 9;   // choose the input pin (for a pushbutton)
// variable to hold the value of the switchPin
int b2switchState = 0;

// variable to hold previous value of the switchpin
int b2prevSwitchState = 0;
int rating = 0;
int finalRatingS1 = 0;
int studentResponse[]= {0, 0, 0};


void setup() {

  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); //receives from S2
  //Wire.onReceive(receiveEvent2); //receives from S3
  
  // set up the number of columns and rows on the LCD 
  lcd.begin(16, 2);
  
  // set up the switch pin as an input
  pinMode(switchPin,INPUT);
  
  // Print a message to the LCD.
  lcd.print("Check Yo Self");
  // set the cursor to column 0, line 1
  // line 1 is the second row, since counting begins with 0
  lcd.setCursor(0, 1);
  // print to the second line
  lcd.print("Do you get it?");
  Serial.begin(9600);      // open the serial port at 9600 bps:  
}

int getBoard (int value) {
  return value/10;
}

int getRating (int value) {
  return value%10;
}

void printList() {
  for (int i=0; i<3; i++) {
    Serial.print(studentResponse[i]);
  }
  Serial.println();
}

int getRatingArrayMax() {
  int firstCompare = max(studentResponse[0], studentResponse[1]);
  int secondCompare = max(firstCompare, studentResponse[2]);
  return secondCompare;
}

int getRatingArrayMin() {
  int firstCompare = min(studentResponse[0], studentResponse[1]);
  int secondCompare = min(firstCompare, studentResponse[2]);
  return secondCompare;
}

void addRatingToList(int value) {
 studentResponse[getBoard(value) - 1] = getRating(value);
 //printList();
 for (int i=0; i<3; i++) {
   if (studentResponse[i]==0) {
     return;
   }
 }
 Serial.print("The highest ranking is: ");
 Serial.println(getRatingArrayMax());
 Serial.print("The lowest ranking is: ");
 Serial.println(getRatingArrayMin()); 
}



void receiveEvent(int howMany)
{
  int finalRatingS2 = Wire.read();
  //Serial.print("S2: ");
  Serial.println(finalRatingS2);
  addRatingToList(finalRatingS2);
  //Serial.println(howMany); //this is a test



  /*int studentResponse[] = {finalRatingS1, finalRatingS2};
  int i;
  //int j;
  if (finalRatingS1 > -1 && finalRatingS2 > -1){
    
    for (i=0; i<3; i=i+1) {
    Serial.print(studentResponse[i]);
    
  }
  
  Serial.println();
  int maxResponse;
  maxResponse = max(studentResponse[0], studentResponse[1]);
  Serial.print(maxResponse);
  
  Serial.println();
  
  int minResponse;
  minResponse = min(studentResponse[1], studentResponse[2]);
  Serial.print(minResponse);
  
  //int compare;
  //compare = max(maxResponse, minResponse);
  //Serial.print(compare);*/
}

void receiveEvent2(int howMany2)
{
  int finalRatingS3 = Wire.read();
  Serial.print("S3: ");
  Serial.println(finalRatingS3);
}

/*void comparison() {
   
  /*int studentResponse[] = {finalRatingS1, finalRatingS2};
  int i;
  //int j;
  if (finalRatingS1 > 0 && finalRatingS2 > 0 && finalRatingS3 > 0){
    
    for (i=0; i<3; i=i+1) {
    Serial.print(studentResponse[i]);
    
  }
  }
  Serial.println();
  int maxResponse;
  maxResponse = max(studentResponse[0], studentResponse[1]);
  Serial.print(maxResponse);
  
  Serial.println();
  
  int minResponse;
  minResponse = min(studentResponse[1], studentResponse[2]);
  Serial.print(minResponse);
  
  int compare;
  compare = max(maxResponse, minResponse);
  Serial.print(compare);
}*/


void loop() {
  // check the status of the switch
  switchState = digitalRead(switchPin);

  // compare the switchState to its previous state
  if (switchState != prevSwitchState) {
    // if the state has changed from HIGH to LOW
    // you know that the ball has been tilted from 
    // one direction to the other 
    if (switchState == LOW) {
      
            // clean up the screen before printing a new reply
      lcd.clear();
      // set the cursor to column 0, line 0     
      lcd.setCursor(0, 0);
      // print some text
      reply++;
      reply%=10;
      
      
      // choose a saying to print baed on the value in reply 
      switch(reply){   
          
        case 0:
        lcd.setCursor(0, 0);
      // print some text
        lcd.print("1: This makes no");
      // move the cursor to the second line
        lcd.setCursor(0, 1);
        lcd.print("sense at all.");
        rating+=1;
        break;

      case 1:
        lcd.print("2: Whoa.");
        lcd.setCursor(0, 1);
        lcd.print("I'm lost.");
        rating+=1; 
        break;
        

      case 2:
        lcd.print("3: There was a");
        lcd.setCursor(0, 1);
        lcd.print("glimmer, but no.");
        rating+=1;
        break;

      case 3:
        lcd.print("4: Not the best,");
        lcd.setCursor(0, 1);
        lcd.print("not the worst.");
        rating+=1;
        break;

      case 4:
        lcd.print("5: On the verge");
        lcd.setCursor(0, 1);
        lcd.print("of getting it.");
        rating+=1;
        break;

      case 5:
        lcd.print("6: I feel a bit");
        lcd.setCursor(0, 1);
        lcd.print("better than ok.");
        rating+=1;
        break;

      case 6:
        lcd.print("7: Not 100, but");
        lcd.setCursor(0, 1);
        lcd.print("I feel good.");
        rating+=1;
        break;

      case 7:
        lcd.print("8: I can explain");
        lcd.setCursor(0, 1);
        lcd.print("most things.");
        rating+=1;
        break;
        
      case 8:
        lcd.print("9: Definitely");
        lcd.setCursor(0, 1);
        lcd.print("solid.");
        rating+=1;
        //Serial.println(rating);
        break;
        
      case 9:
        lcd.print("10: Move over,");
        lcd.setCursor(0, 1);
        lcd.print("I'll teach this.");
        rating+=1;
        break;
      }
    }

  }
  
  
    b2switchState = digitalRead(inPin);  // read input value
  
    if (b2switchState != b2prevSwitchState) {
      if (b2switchState == HIGH) {         // check if the input is HIGH (button released)
          //Serial.println("selected!");
          finalRatingS1 = 10 + rating%10;
          Serial.println(finalRatingS1);
          addRatingToList(finalRatingS1);  
      } 
      
      
    }


  b2prevSwitchState = b2switchState;
  // save the current switch state as the last state 
  prevSwitchState = switchState;

}

No comments:

Post a Comment