Go Down

Topic: Multiple Controller Payment System Project (Read 800 times) previous topic - next topic

dekdimaya

hi i have coded the program , please see below code. I have tested it and it is running from my PC, I have created sample c# program to send data/message and it is working... help me with below code for signaling.. thanks

Quote
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE);

int C1W01Pin = 2, C2W01Pin = 3, CSW01Pin = 4; //washer#01
int C1D01Pin = 5, C2D01Pin = 6, CSD01Pin = 7; //dryer#01

int C1W02Pin = 8, C2W02Pin = 9, CSW02Pin = 10; //washer#02
int C1D02Pin = 11, C2D02Pin = 12, CSD02Pin = 13; //dryer#02

/*
 * More Pins for Arduino Mega
 */

void setup() {
 
  Serial.begin(9600);
 
  lcd.begin(16,2);
  lcdReset();
  }

void loop() { }

void lcdReset()
{
    lcd.clear();
    lcd.print("Ready... ");
    lcd.setCursor(8,1);
    lcd.print("-ns");
  }

 void lcdDisplay(String r1, String r2, int d)
 {
    lcd.clear();
    lcd.print(r1);
    lcd.setCursor(0,1);
    lcd.print(r2);   
   
    delay(d);
    lcdReset();
  }

void serialEvent() {
 
  String rcv; 
  if(Serial.available() > 0) { rcv = Serial.readString(); }

  String cmd = rcv.substring(0,5);
  if (cmd == "COIN1")  {   
    command(rcv.substring(6,9), rcv.substring(10,12).toInt(), rcv.substring(13,16).toInt(), 1);
    return;
    }   
  else if (cmd == "COIN2")  {
    command(rcv.substring(6,9), rcv.substring(10,12).toInt(), rcv.substring(13,16).toInt(), 2);
    return;
    }
  else if (cmd == "COINS")  {
    command(rcv.substring(6,9), rcv.substring(10,12).toInt(), rcv.substring(13,16).toInt(), 3);
    return;
    }
   
  lcdDisplay("Invalid Command", "", 3000);
  }

void command(String m, int t, int p, int type)
{
  if (m == "W01")  {
    switch (type) {
      case 1:
        lcdDisplay(String(type) + "WASHER " + m, "PIN" + String(C1W01Pin), 6000); 
        sendCoinSignal(C1W01Pin , t, p);       
        break;
     
      case 2:
        lcdDisplay(String(type) + "WASHER " + m, "PIN" + String(C2W01Pin), 6000);
        sendCoinSignal(C2W01Pin , t, p);
        break;
     
      case 3:
        lcdDisplay(String(type) + "WASHER " + m, "PIN" + String(CSW01Pin), 6000);
        sendSwitchSignal(CSW01Pin , t, p);
      break;     
    }
 
  }

  if (m == "D01")  {
    switch (type) {
      case 1:
        lcdDisplay(String(type) + "DRYER " + m, "PIN" + String(C1D01Pin), 6000); 
        sendCoinSignal(C1D01Pin , t, p);       
        break;
     
      case 2:
        lcdDisplay(String(type) + "DRYER " + m, "PIN" + String(C2D01Pin), 6000);
        sendCoinSignal(C2D01Pin , t, p);
        break;
     
      case 3:
        lcdDisplay(String(type) + "DRYER " + m, "PIN" + String(CSD01Pin), 6000);
        sendSwitchSignal(CSD01Pin , t, p);
      break;     
    }
 
  }

  if (m == "W02")  {
    switch (type) {
      case 1:
        lcdDisplay(String(type) + "WASHER " + m, "PIN" + String(C1W02Pin), 6000); 
        sendCoinSignal(C1W02Pin , t, p);       
        break;
     
      case 2:
        lcdDisplay(String(type) + "WASHER " + m, "PIN" + String(C2W02Pin), 6000);
        sendCoinSignal(C2W02Pin , t, p);
        break;
     
      case 3:
        lcdDisplay(String(type) + "WASHER " + m, "PIN" + String(CSW02Pin), 6000);
        sendSwitchSignal(CSW02Pin , t, p);
      break;     
    }
 
  }

  if (m == "D02")  {
    switch (type) {
      case 1:
        lcdDisplay(String(type) + "DRYER " + m, "PIN" + String(C1D02Pin), 6000); 
        sendCoinSignal(C1D02Pin , t, p);       
        break;
     
      case 2:
        lcdDisplay(String(type) + "DRYER " + m, "PIN" + String(C2D02Pin), 6000);
        sendCoinSignal(C2D02Pin , t, p);
        break;
     
      case 3:
        lcdDisplay(String(type) + "DRYER " + m, "PIN" + String(CSD02Pin), 6000);
        sendSwitchSignal(CSD02Pin , t, p);
      break;     
    }
 
  }

}

void sendCoinSignal(int pin, int token, int pulse){

  lcdDisplay(String(pin),String(token) + " X TOKEN",3000);
  /*
   * HELP me with this one.
   * pin = Pin number to send pulses/signal
   * pulse = pulse width
   * token = number of token/pulse to send
   */
 
}


void sendSwitchSignal(int pin, int on, int pulse){
  lcdDisplay(String(pin), String(on) + "SENDING SWITCH" ,3000);
 
/*
   * HELP me with this one.
   * pin = Pin number to send pulses/signal
   * pulse = pulse width
   */
 
}



/*

int getMachine(String& m){
 
  int r = m.substring(1,4).toInt();
  m = m.substring(0,1); 
 
  return r;
  }
*/

Please help me with this two function. how to send signal according picture i send before.. Hope answer me or any input will appreciate. Thank you

Quote
void sendCoinSignal(int pin, int token, int pulse){

  lcdDisplay(String(pin),String(token) + " X TOKEN",3000);
  /*
   * HELP me with this one.
   * pin = Pin number to send pulses/signal
   * pulse = pulse width
   * token = number of token/pulse to send
   */
 
}

void sendSwitchSignal(int pin, int on, int pulse){
  lcdDisplay(String(pin), String(on) + "SENDING SWITCH" ,3000);
 
/*
   * HELP me with this one.
   * pin = Pin number to send pulses/signal
   * pulse = pulse width
   */
 
}

Go Up