daily pastebin goal
6%
SHARE
TWEET

Untitled

malleryj20 Feb 19th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int cclock = 0;
  2. int lstfed = 0;
  3. int mood = 3000;
  4. int lastplayed = 0;
  5.  
  6. #include <Wire.h>
  7. #include <LiquidCrystal_I2C.h>
  8. #include "LedControl.h" //  need the library
  9.  
  10. LedControl lc=LedControl(1,2,3,1); //
  11. LiquidCrystal_I2C lcd(0x3F, 16, 2);
  12.  
  13.  
  14. // pin 12 is connected to the MAX7219 pin 1
  15. // pin 11 is connected to the CLK pin 13
  16. // pin 10 is connected to LOAD pin 12
  17. // 1 as we are only using 1 MAX7219
  18.  
  19. void setup()
  20. {
  21.   lcd.begin();
  22.   pinMode(12, INPUT);
  23.   pinMode(8, INPUT);
  24.   pinMode(5, OUTPUT);
  25.  
  26.   // Turn on the blacklight
  27.   lcd.setBacklight((uint8_t)1);
  28.   lc.shutdown(0,false);
  29.   lc.setIntensity(0,8);
  30.   lc.clearDisplay(0);
  31. lc.setLed(0,0,0,true);
  32. lc.setLed(0,0,1,true);
  33. lc.setLed(0,1,0,true);
  34. lc.setLed(0,1,1,true);
  35. lcd.print("Hello!");
  36. tone(5, 300, 400);
  37. delay(400);
  38. tone(5, 400, 400);
  39. lcd.clear();
  40.  
  41. }
  42.  
  43. void loop()
  44. {
  45.   delay(200);
  46.   lcd.clear();
  47.   cclock++;
  48.   mood--;
  49.   if (digitalRead(12)){
  50.     lstfed = cclock;
  51.     lcd.print("You feed the pet");
  52.     lcd.setCursor(0, 1);
  53.     lcd.print("It chows down");
  54.     lcd.setCursor(0, 0);
  55.     tone(5, 300, 400);
  56. delay(400);
  57. tone(5, 400, 400);
  58.     delay(1600);
  59.   }
  60.   else if (digitalRead(8)){
  61.     if (cclock - lastplayed > 300){
  62.     mood += 600 - (cclock - lstfed);
  63.     lastplayed = cclock;
  64.     if (mood > 3000){
  65.       mood = 3000;
  66.     }
  67.     lcd.print("You played with");
  68.     lcd.setCursor(0, 1);
  69.     lcd.print("the pet!");
  70.     lcd.setCursor(0, 0);
  71.     tone(5, 300, 400);
  72. delay(400);
  73. tone(5, 400, 400);
  74.     delay(1600);
  75.     }
  76.     else{
  77.       lcd.print("The pet didnt");
  78.     lcd.setCursor(0, 1);
  79.     lcd.print("want to play");
  80.     lcd.setCursor(0, 0);
  81.     delay(2000);
  82.     }
  83.   }
  84.   else{
  85.     if (mood > 2200){
  86.       lcd.print("Mood: Happy");
  87.     }
  88.     else if (mood >1400){
  89.       lcd.print("Mood: Lonely");
  90.     }
  91.     else{
  92.       lcd.print("Mood: Sad");
  93.     }
  94.     lcd.setCursor(0, 1);
  95.     if (cclock - lstfed > 700){
  96.       lcd.print("Hungry");
  97.     }
  98.     else{
  99.       lcd.print("Full");
  100.     }
  101.     lcd.setCursor(0,0);
  102.     }
  103. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top