Kiso (Previously the Love Bot 3000)

The Code for each Arduino!

One Arduino contains the code for the TVOut library, while the other contains the code for the sensors. The two communicate with one another by sending one bit signals back and forth (through the TX and RX pins, respectively), triggering various loops to function.  This is done because the TVOut library is nearly incompatible with the smaller LCD screen and delay() functions. Find the library HERE and click below to get the code! (There are other forks of the same code, though used for the Mega!)

Arduino #1 – TVOut

Note: The zeros, while seeming odd, are actually the faces that appear on the screen! When formatted correctly in the Arduino (like, copying and pasting the code into it) they appear right!

#include
#include
#include “schematic.h”
#include “TVOlogo.h”
#include

TVout TV;

float zOff = 150;
float xOff = 0;
float yOff = 0;
float cSize = 50;
float view_plane = 64;
float angle = PI / 60;

//Ultrasonic Sensor

// defines pins numbers
const int trigPin = 3;
const int echoPin = 5;
// defines variables
long duration;
int distance;
int time;
int closeTime;
int awayTime;
int timeTime = 22;

//Connection to other Arduino
int incomingByte; // a variable to read incoming serial data into
const int ledPin = 13; // the pin that the LED is attached to
int lastByte;

void setup() {
Serial.begin(9600);
TV.begin(NTSC, 120, 96);
TV.select_font(font8x8);
// intro();
TV.println(“I got this!”);

//SCREEN TAKES 14 CHARACTERS ACROSS FOR EVERY LINE
//SCREEN TAKES 11 LINES

//Communication with other Arduino
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);

}

void loop() {

// see if there’s incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();

if (incomingByte == ‘A’)
{
closeTime++;
awayTime = 0;
if (closeTime == 1) {
TV.clear_screen();
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0000 “);
Serial.print(‘A’);
}
if (closeTime == 11) {
TV.clear_screen();
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 000000 “);
Serial.print(‘B’);
}
if (closeTime == 23) {
TV.clear_screen();
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 000000 “);
TV.println(” “);
Serial.print(‘C’);
}
if (closeTime == 35) {
TV.clear_screen();
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 00000000 “);
TV.println(” “);

Serial.print(‘D’);
}
if (closeTime == 47) {
TV.clear_screen();
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 00000000 “);
}
if (closeTime > 47) {
Serial.print(‘E’);
}
}
if (incomingByte == ‘B’)
{
awayTime++;
closeTime = 0;
if (awayTime == 1) {
TV.clear_screen();
Serial.print(‘V’);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” “);
TV.println(” “);
TV.println(” 0000000000 “);
TV.println(” “);
}
if (awayTime == 11) {
TV.clear_screen();
Serial.print(‘W’);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” “);
TV.println(” 00000000 “);
TV.println(” “);
TV.println(” “);
}
if (awayTime == 21) {
TV.clear_screen();
Serial.print(‘X’);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” 000000 “);
TV.println(” “);
TV.println(” “);
TV.println(” “);
}
if (awayTime == 31) {
TV.clear_screen();
Serial.print(‘Y’);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” 000000 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” “);
}
if (awayTime == 41) {
TV.clear_screen();
Serial.print(‘Z’);
TV.println(” “);
TV.println(” 00 00 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 0 0 0 0 “);
TV.println(” 00 00 “);
TV.println(” “);
TV.println(” “);
TV.println(” 000000 “);
TV.println(” 00 00 “);
TV.println(“00 00”);
}
if (awayTime > 41) {
Serial.print(‘Z’);
}
}

// lastByte = incomingByte;
// Serial.print(closeTime);
}
}

Arduino #2 – Ultrasonic Sensor and Small LCD Screen

// Ultrasonic Sensor

// Pins
const int trigPin = 6;
const int echoPin = 10;
// Variables
long duration;
int distance;

float distance1 = 50;
float distance2 = 50;
bool trueDist;

int count;

int incomingByte;

//LCD Screen

// include the library code:
#include

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 13, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//Smoothing

// Define the number of samples to keep track of. The higher the number, the
// more the readings will be smoothed, but the slower the output will respond to
// the input. Using a constant rather than a normal variable lets us use this
// value to determine the size of the readings array.
const int numReadings = 10;

int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int counterSadRobo = 0;

int counterSaddest = 0;

int counterHappyRobo = 0;

int counterHappiest = 0;

void setup() {
Serial.begin(9600);

// Ultrasonic Sensor

pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication

//LCD Screen
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
lcd.print(“I am working!”);

// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } } void loop() { // Serial.print(‘H’); // delay(2000); // Serial.print(‘L’); // delay(2000); //Ultrasonic Sensor // Clears the trigPin digitalWrite(trigPin, LOW); delay(2); // Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin, HIGH); delay(250); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculating the distance distance = duration * 0.034 / 2; distance1 = distance; if (distance > 105) {
count++;
distance = 105;
}

if (count > 10) {
}

// subtract the last reading:
total = total – readings[readIndex];
// read from the sensor:
readings[readIndex] = distance;
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;

// if we’re at the end of the array…
if (readIndex >= numReadings) {
// …wrap around to the beginning:
readIndex = 0;
}

// calculate the average:
average = total / numReadings;
// average = 105;
// send it to the computer as ASCII digits
Serial.println(average);
delay(1); // delay in between reads for stability

// Prints the distance on the Serial Monitor
// Serial.print(“Distance: “);
// Serial.println(distance);

if (average < 104) { Serial.print(‘A’); } if (average > 104) {
Serial.print(‘B’);
}
// Serial.println(distance);

if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();

//HAPPY/ CLOSE/ SENSED VALUES

if (incomingByte == ‘A’) {
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(“Hello!”);
}

if (incomingByte == ‘B’) {
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(“How are you”);
lcd.setCursor(0, 1);
lcd.print(“doing today?”);
}

if (incomingByte == ‘C’) {
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(“Oh, is that”);
lcd.setCursor(0, 1);
lcd.print(“right?”);
}

if (incomingByte == ‘D’) {
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(“I’m having a”);
lcd.setCursor(0, 1);
lcd.print(“great time!”);
counterHappyRobo = 0;
}

if (incomingByte == ‘E’) {
counterHappyRobo++;
Serial.println(counterHappyRobo);
if (counterHappyRobo >= 0 && counterHappyRobo <= 10) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“Hey, just so”); lcd.setCursor(0, 1); lcd.print(“you know…”); } if (counterHappyRobo >= 11 && counterHappyRobo <= 21) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“This means a”); lcd.setCursor(0, 1); lcd.print(“lot to me.”); } if (counterHappyRobo >= 22 && counterHappyRobo <= 32) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“Nobody really”); lcd.setCursor(0, 1); lcd.print(“stops anymore.”); } if (counterHappyRobo >= 33 && counterHappyRobo <= 43) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“They’ve all”); lcd.setCursor(0, 1); lcd.print(“forgotten me…”); } if (counterHappyRobo >= 44 && counterHappyRobo <= 54) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“Even though I”); lcd.setCursor(0, 1); lcd.print(“know the same…”); } if (counterHappyRobo >= 55 && counterHappyRobo <= 65) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“thing is gonna”); lcd.setCursor(0, 1); lcd.print(“happen here…”); } if (counterHappyRobo >= 66 && counterHappyRobo <= 76) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“I won’t forget”); lcd.setCursor(0, 1); lcd.print(“you!”); } if (counterHappyRobo >= 77 && counterHappyRobo <= 87) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“Wait, do you”); lcd.setCursor(0, 1); lcd.print(“think maybe…”); } if (counterHappyRobo >= 88 && counterHappyRobo <= 98) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“you could take”); lcd.setCursor(0, 1); lcd.print(“me with you?”); } if (counterHappyRobo >= 99 && counterHappyRobo <= 109) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“I won’t bother”); lcd.setCursor(0, 1); lcd.print(“you or anything!”); } if (counterHappyRobo >= 110 && counterHappyRobo <= 120) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“I’ll be good!”); } if (counterHappyRobo >= 121 && counterHappyRobo <= 131) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“I promise!”); counterHappiest = 0; } if (counterHappyRobo >= 132)
{
counterHappiest++;
int lcdDisplay = random(0, 4);
if (lcdDisplay == 0 || lcdDisplay == 1)
{
lcd.clear();
int stringcharCount = 8;
int upperbound = 17 – stringcharCount;
lcd.setCursor(random(0, upperbound), random(0, 2));
lcd.print(“Take me!”);
}

else if (lcdDisplay == 2 || lcdDisplay == 3)
{
lcd.clear();
int stringcharCount = 8;
int upperbound = 17 – stringcharCount;
lcd.setCursor(random(0, upperbound), random(0, 2));
lcd.print(“Save me!”);
}
}

}

//SAD/ FAR/ NOT SENSED VALUES

if (incomingByte == ‘V’) {
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(“Wait…”);
}

if (incomingByte == ‘W’) {
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(“Where did you”);
lcd.setCursor(0, 1);
lcd.print(“go?”);
}

if (incomingByte == ‘X’) {
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(“Did I do”);
lcd.setCursor(0, 1);
lcd.print(“something wrong?”);
}

if (incomingByte == ‘Y’) {
counterSadRobo = 0;
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(“Please come”);
lcd.setCursor(0, 1);
lcd.print(“back!”);
}

if (incomingByte == ‘Z’) {
counterSadRobo++;
Serial.println(counterSadRobo);
if (counterSadRobo >= 0 && counterSadRobo <= 7) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“No…”); } else if (counterSadRobo >= 8 && counterSadRobo <= 14) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“No, no…”); } else if (counterSadRobo >= 15 && counterSadRobo <= 23) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“No, no, no!”); } else if (counterSadRobo >= 24 && counterSadRobo <= 34) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“This isn’t fair!”); } else if (counterSadRobo >= 35 && counterSadRobo <= 45) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“I didn’t do”); lcd.setCursor(0, 1); lcd.print(“anything wrong!”); } else if (counterSadRobo >= 46 && counterSadRobo <= 56) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“Why do they”); lcd.setCursor(0, 1); lcd.print(“leave?!”); } else if (counterSadRobo >= 57 && counterSadRobo <= 67) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“Why do they all”); lcd.setCursor(0, 1); lcd.print(“… leave…?”); } else if (counterSadRobo >= 67 && counterSadRobo <= 77) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“I’m sorry, I…”); } else if (counterSadRobo >= 78 && counterSadRobo <= 88) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“I just…”); } else if (counterSadRobo >= 89 && counterSadRobo <= 99) { lcd.setCursor(0, 0); lcd.clear(); lcd.print(“I want you to”); lcd.setCursor(0, 1); lcd.print(“come back…”); } else if (counterSadRobo >= 100)
{
int lcdDisplay = random(0, 3);
if (lcdDisplay == 0)
{
int stringcharCount = 6;
int upperbound = 17 – stringcharCount;
lcd.setCursor(random(0, upperbound), random(0, 2));
lcd.print(“Please”);
}

else if (lcdDisplay == 1)
{
int stringcharCount = 9;
int upperbound = 17 – stringcharCount;
lcd.setCursor(random(0, upperbound), random(0, 2));
lcd.print(“Please…”);
}

else if (lcdDisplay == 2)
{
int stringcharCount = 7;
int upperbound = 17 – stringcharCount;
lcd.setCursor(random(0, upperbound), random(0, 2));
lcd.print(“Please!”);
}
}

// no.
// no, no.
// nonononononono!
// This isn’t fair!
// I didn’t do anything wrong!
// Why?
// Why did you leave?
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s