Joyce LiuFelix LiYang Zhao
Published

deCart

a cart that drives you to give.

Full instructions provided2,703
deCart

Things used in this project

Story

Read more

Custom parts and enclosures

futureDesign.stl

Sketchfab still processing.

Code

decart2.ino

C/C++
decart2.ino
/*
 Decart Arduino Code
 Author: Felix Li
 */

#include <LiquidCrystal.h>
#include <Wtv020sd16p.h>
#include <SoftwareSerial.h>  

//---------LCD DISPLAY---------

//Pin Layout
#define RS 13
#define E 12

#define D4 6
#define D5 7
#define D6 9
#define D7 8

#define NUM_COLS 16
#define NUM_ROWS 2

LiquidCrystal lcd(RS, E, D4, D5, D6, D7);

//---------SOUND MODULE---------
#define resetPin 2  // The pin number of the reset pin.
#define clockPin 3   // The pin number of the clock pin.
#define dataPin 4   // The pin number of the data pin.
#define busyPin 5   // The pin number of the busy pin.
#define shutDownPin 23

Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);


//---------PROGRESS BAR---------
#define LED10 24
#define LED9 26
#define LED8 28
#define LED7 30

#define LED6 40
#define LED5 42
#define LED4 44
#define LED3 46
#define LED2 48
#define LED1 50

//---------SELFISH LIGHT---------
#define SELF_LED 29
unsigned long lastTime = 0;
int TOGGLE = 200;
boolean SELFISH = true;

//---------BLUETOOTH MODULE---------
#define bluetoothTx 10
#define bluetoothRx 11

//---------PIEZO SENSOR---------
#define PIEZO A2
#define TIME_DELAY 1500
int THRESHOLD = 30;
unsigned long SOUND_NOISE = 0;
boolean NOISY = false;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

//---------GLOBAL VARIABLES/STATES---------
#define PERSONAL 0
#define CHARITY 1
#define NUM_OF_MODES 2
int mode = PERSONAL;
int personal_donations = 0;

void setup() {
  //Initializes the module.
  Serial.begin(9600);

  bluetooth.begin(115200);  // The Bluetooth Mate defaults to 115200bps
  bluetooth.print("$");  // Print three times individually
  bluetooth.print("$");
  bluetooth.print("$");  // Enter command mode
  delay(100);  // Short delay, wait for the Mate to send back CMD
  bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
 
  lcd.begin(NUM_COLS, NUM_ROWS);

  pinMode(shutDownPin, OUTPUT);
  digitalWrite(shutDownPin, LOW); 
  wtv020sd16p.reset();
 
  pinMode(LED1, OUTPUT); 
  pinMode(LED2, OUTPUT); 
  pinMode(LED3, OUTPUT); 
  pinMode(LED4, OUTPUT); 

  pinMode(LED5, OUTPUT); 
  pinMode(LED6, OUTPUT); 
  pinMode(LED7, OUTPUT); 
  pinMode(LED8, OUTPUT); 
  pinMode(LED9, OUTPUT); 
  pinMode(LED10, OUTPUT); 
  pinMode(SELF_LED, OUTPUT); 


  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  digitalWrite(LED4, HIGH);
  digitalWrite(LED5, HIGH);
  digitalWrite(LED6, HIGH);
  digitalWrite(LED7, HIGH);
  digitalWrite(LED8, HIGH);
  digitalWrite(LED9, HIGH);
  digitalWrite(LED10, HIGH);  
  
//  digitalWrite(LED1, LOW);
//  digitalWrite(LED2, LOW);
//  digitalWrite(LED3, LOW);
//  digitalWrite(LED4, LOW);
//  digitalWrite(LED5, LOW);
//  digitalWrite(LED6, LOW);
//  digitalWrite(LED7, LOW);
//  digitalWrite(LED8, LOW);
//  digitalWrite(LED9, LOW);
//  digitalWrite(LED10, LOW);   
  
  digitalWrite(SELF_LED, HIGH);


  //Default mode to charity
  toggle_mode();
}

void toggle_selfish() {
  digitalWrite(SELF_LED, digitalRead(SELF_LED) ^ 1);  
}

void write_led(int led, int intensity) {
  switch (led) {
   case 1:
     digitalWrite(LED1, intensity);
     break;
   case 2:
     digitalWrite(LED2, intensity);
     break;
   case 3:
     digitalWrite(LED3, intensity);
     break;
   case 4:
     digitalWrite(LED4, intensity);
     break;
   case 5:
     digitalWrite(LED5, intensity);
     break;
   case 6:
     digitalWrite(LED6, intensity);
     break;
   case 7:
     digitalWrite(LED7, intensity);
     break;
   case 8:
     digitalWrite(LED8, intensity);
     break;
   case 9:
     digitalWrite(LED9, intensity);
     break;
   case 10:
     digitalWrite(LED10, intensity);
     break; 
  }   
}

void donation_led() {
   for (int i = 1; i < personal_donations+1; i++) {
      write_led(i, HIGH);  
    }
    
    for (int i = personal_donations+1; i < 11; i++) {
      write_led(i, LOW);  
    }
 
}

void toggle_mode() {
  mode += 1;
  mode = mode%2;  
  switch(mode) {
    case PERSONAL:
      {
        
       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print("Your Donations!");
       lcd.setCursor(0,1);
       lcd.print("Contribution: " + String(personal_donations));
        
       donation_led();       
        break; 
      }
      
    case CHARITY:
      {
        
       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print("Charity Goal!");
       lcd.setCursor(0,1);
       lcd.print("Percentage: 30%");
        
        //hardcoded to always be 30%
        write_led(1, HIGH);
        write_led(2, HIGH);
        write_led(3, HIGH);
        write_led(4, LOW);
        write_led(5, LOW);
        write_led(6, LOW);
        write_led(7, LOW);
        write_led(8, LOW);
        write_led(9, LOW);
        write_led(10, LOW);
        break;
     }
    
    
  }
  
  delay(100);


}

void update_donations() {
  digitalWrite(shutDownPin, HIGH);
  if (personal_donations < 10) {
    personal_donations += 1;
    TOGGLE += 100;
    if (personal_donations == 10) {
      SELFISH = false;
      wtv020sd16p.asyncPlayVoice(2);
      digitalWrite(SELF_LED, LOW);
      //play sound for complete donations
      lcd.setCursor(0, 0);
      lcd.print("Selfless!");
      lcd.setCursor(0,1);
      lcd.print("Contribution: " + String(personal_donations));  
    } 
  }
  
    
  if (personal_donations != 10) {
    wtv020sd16p.asyncPlayVoice(0);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Donated!");
    lcd.setCursor(0,1);
    lcd.print("Contribution:" + String(personal_donations));  
  }
  
  donation_led();
  NOISY = true;  
  SOUND_NOISE = millis() + TIME_DELAY;
}

void loop() {
  // play sound file 0 
  int piezo_in = analogRead(PIEZO);
//  Serial.println("Current Time:" + String(millis()));
//  Serial.println("SOUND-NOISE:" + String(SOUND_NOISE));
//  Serial.println("NOISY " + String(NOISY));
// 
  if (NOISY) {
    if (millis() > SOUND_NOISE) {
      NOISY = false;
      digitalWrite(shutDownPin, LOW);      
    }    
  } else {
  
    if (piezo_in > THRESHOLD) {
      toggle_mode();
    }    
  }
  
  if (millis() > (lastTime + TOGGLE) && SELFISH) {
    toggle_selfish();
    lastTime = millis();
  }
 
  if(bluetooth.available())  // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor
    
    char received = (char) bluetooth.read();
    Serial.print(received);  
    
    if (received == '1') {
      update_donations();
    } else {
      digitalWrite(shutDownPin, HIGH);
      SOUND_NOISE = millis() + TIME_DELAY;
      NOISY = true;  
      wtv020sd16p.asyncPlayVoice(1);       
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Not a good");
      lcd.setCursor(0,1);
      lcd.print("charity item.");  

    }
  }
  
  
  
}

Github

Credits

Joyce Liu

Joyce Liu

7 projects • 1 follower
cm2014-fa02
Felix Li

Felix Li

4 projects • 2 followers
I'm dope, yo.
Yang Zhao

Yang Zhao

4 projects • 1 follower
4th year, Computer Science (HCI)

Comments