Interface
//sketch created by WahyuCF 2021
/*
* Serial1 TX=PIN18 RX=PIN19
*/
#include <Wire.h>
#include <EEPROM.h>
int myInts[6];
int myPins[43] = {A0, A2, A4, A6, A8, A10, A14, A1, A3, A5, A7, A9, A11, A15, 34, 36, 38, 40, 42, 44, 46, 35, 37, 39, 41, 43, 45, 47, 2, 4, 6, 8, 10, 14, 16, 22, 3, 5, 7, 9, 11, 15, 17};
int mySensVals[43] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int count = 0;
int count1= 0;
int JmlLine = 43;
int timer = 100;
int timer1 = 900;
int timer2 = 100;
int a=0;
char str[16];
int id;
int idS;
int idS1=0;
bool valTot = HIGH; // variable to store the read value
unsigned long interval=500; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long.
void setup()
{
Serial.begin(9600);
Serial2.begin(9600);
Serial.println("System Started");
delay(5000);
for (count=0;count<JmlLine;count++) {
pinMode(myPins[count], INPUT);
digitalWrite(myPins[count], HIGH);
}
pinMode(13, OUTPUT); // sets the digital pin 13 as output
digitalWrite(13, LOW); // sets the digital pin 13 off
CodeOn();
}
void CodeOn(){
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13 , LOW);
}
void CodeOn1(){
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13 , LOW);
delay(200);
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13 , LOW);
}
void loop()
{
idS1 =0;
valTot = HIGH;
for (count=0;count<JmlLine;count++) {
mySensVals[count] = digitalRead(myPins[count]);
if (mySensVals[count] == LOW) {
valTot = valTot && mySensVals[count];
}
}
if (valTot == LOW){
for (count=0;count<JmlLine;) {
mySensVals[count] = digitalRead(myPins[count]);
delay(10);
if ( mySensVals[count] == LOW){
if (idS1 == 0){
count1=count+1;
Serial2.print(count1);
Serial2.println(":");
delay(timer2);
CodeOn1();
a=count;
sprintf(str,"%d", a); // use sprintf() to compose the string str
idS1 =1;
}
while (Serial2.available()){
String cmds = Serial2.readStringUntil(':');
delay(timer2);
idS1 = atoi((const char *) cmds.c_str());
delay(timer2);
count++;
}
}
else {
count++;
}
}
count=0;
}
CodeOn();
if (valTot == HIGH){
Serial2.println("50:");
delay(500);
}
}
single DMD display
/*
single DMD display
*/
#include <SPI.h>
//#include <SoftwareSerial.h>
#include <DMD2.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_12.h>
#define DISPLAYS_ACROSS 2
#define DISPLAYS_DOWN 1
const int COUNTDOWN_FROM = 12;
int counter = COUNTDOWN_FROM;
uint16_t lastPrint=100;
String state;
boolean ret=false;
int NoQ=0;
int id;
unsigned long interval=10000; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long.
//SoftwareSerial mySerial1(2, 3); // RX, TX
SoftDMD dmd(DISPLAYS_ACROSS,DISPLAYS_DOWN); // DMD controls the entire display
DMD_TextBox box(dmd, 0,0); // "box" provides a text box to automatically write to/scroll the display
// the setup routine runs once when you press reset:
void drawText(String dispString)
{
dmd.clearScreen();
int sLength = dispString.length();
dmd.drawString(1, 1, dispString);
}
void beepCB()
{
digitalWrite(4, HIGH);
delay(100);
digitalWrite(4, LOW);
delay(100);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(4, LOW);
delay(100);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(4, LOW);
}
void beeppendek()
{
digitalWrite(4, HIGH);
delay(100);
digitalWrite(4, LOW);
}
void beeppanjang()
{
digitalWrite(4, HIGH);
delay(300);
digitalWrite(4, LOW);
}
void DispBed(String a)
{
String b = a+"-Bed";
// Serial.print ("Tampil: ");
// Serial.println (b);
drawText(b);
beeppendek();
delay(900);
dmd.clearScreen();
delay(500);
drawText(b);
beeppendek();
delay(900);
dmd.clearScreen();
delay(500);
drawText(b);
beeppendek();
delay(900);
dmd.clearScreen();
delay(500);
drawText(b);
beeppendek();
delay(1000);
dmd.clearScreen();
Serial.println("0:");
digitalWrite(10,HIGH);
delay(200);
digitalWrite(10,LOW);
}
void DispRBed(String a, String c)
{
String b = a+"-B"+c;
// Serial.print ("Tampil: ");
// Serial.println (b);
drawText(b);
beeppendek();
delay(900);
dmd.clearScreen();
delay(500);
drawText(b);
beeppendek();
delay(900);
dmd.clearScreen();
delay(500);
drawText(b);
beeppendek();
delay(900);
dmd.clearScreen();
delay(500);
drawText(b);
beeppendek();
delay(1000);
dmd.clearScreen();
Serial.println("0:");
digitalWrite(10,HIGH);
delay(200);
digitalWrite(10,LOW);
}
void DispKM(String a)
{
String b = a+"-KM";
// Serial.print ("Tampil: ");
// Serial.println (b);
drawText(b);
beeppanjang();
delay(500);
dmd.clearScreen();
delay(500);
drawText(b);
beeppanjang();
delay(500);
dmd.clearScreen();
delay(500);
drawText(b);
beeppanjang();
delay(500);
dmd.clearScreen();
delay(500);
drawText(b);
beeppanjang();
delay(1000);
dmd.clearScreen();
Serial.println("0:");
digitalWrite(10,HIGH);
delay(200);
digitalWrite(10,LOW);
}
void DispCBlue(String a)
{
String b = a+"-C.BL";
// Serial.print ("Tampil: ");
// Serial.println (b);
drawText(b);
beepCB();
delay(900);
dmd.clearScreen();
delay(500);
drawText(b);
beepCB();
delay(500);
dmd.clearScreen();
delay(500);
drawText(b);
beepCB();
delay(900);
dmd.clearScreen();
delay(500);
drawText(b);
beepCB();
delay(1000);
dmd.clearScreen();
Serial.println("0:");
digitalWrite(10,HIGH);
delay(200);
digitalWrite(10,LOW);
}
int phase = 0;
void DotFly() {
dmd.clearScreen();
dmd.drawString(0, 0, F("."));
int steps = random(64); // Each time we scroll a random distance
for(int i = 0; i < steps; i++) {
dmd.drawString(i, 0, F("."));
delay(50);
}
// Move to the next phase
phase = (phase + 1) % 4;
}
void setup() {
Serial.begin(9600);
// mySerial1.begin( 9600 ); // baud-rate of RS485
pinMode (10, OUTPUT);
dmd.setBrightness(50);
dmd.selectFont(Arial_Black_16);
dmd.begin();
dmd.clearScreen();
drawText(" Nurse ");
pinMode(4, OUTPUT); // sets the digital pin 4 as output
digitalWrite(4, HIGH);
delay(200);
digitalWrite(10, HIGH);
digitalWrite(4, LOW);
delay( 400 );
digitalWrite(10, LOW);
digitalWrite(4, HIGH);
delay(200);
digitalWrite(10, HIGH);
digitalWrite(4, LOW);
delay( 400 );
digitalWrite(10, LOW);
digitalWrite(4, HIGH);
digitalWrite(10, HIGH);
delay(1000);
digitalWrite(4, LOW);
delay( 400 );
digitalWrite(10, LOW);
digitalWrite(4, HIGH);
delay(200);
digitalWrite(10, HIGH);
digitalWrite(4, LOW);
delay( 400 );
digitalWrite(10, LOW);
delay(2000);
dmd.clearScreen();
//Serial.println ("Sub Start");
}
// the loop routine runs over and over again forever:
void loop() {
byte b;
while (Serial.available() > 0)
{
// NoQ=1;
String cmds = Serial.readStringUntil(':');
// String vals = mySerial1.readStringUntil(';');
// state=vals;
// Serial.print ("cmds in: ");
// Serial.println (cmds);
id = atoi((const char *) cmds.c_str());
// id=id-3;
// Serial.print ("Serial in: ");
// Serial.println (id);
}
switch (id) {
case 1:
DispCBlue("101");
break;
case 2:
DispBed("101");
break;
case 3:
DispKM("101");
break;
case 4:
DispCBlue("102");
break;
case 5:
DispRBed("102","1");
break;
case 6:
DispRBed("102","2");
break;
case 7:
DispKM("202");
break;
case 8:
DispCBlue("203");
break;
case 9:
DispBed("203");
break;
case 10:
DispKM("203");
break;
case 11:
DispCBlue("4");
break;
case 12:
DispBed("4");
break;
case 13:
DispKM("4");
break;
case 14:
DispCBlue("5");
break;
case 15:
DispRBed("5","1");
break;
case 16:
DispRBed("5","2");
break;
case 17:
DispRBed("5","3");
break;
case 18:
DispKM("6");
break;
case 19:
DispKM("6");
break;
case 20:
DispKM("6");
break;
case 21:
DispKM("6");
break;
case 22:
DispKM("6");
break;
case 23:
DispKM("6");
break;
case 24:
DispKM("6");
break;
case 25:
DispKM("6");
break;
case 26:
DispKM("6");
break;
case 27:
DispKM("6");
break;
case 28:
DispKM("6");
break;
case 29:
DispKM("6");
break;
case 30:
DispKM("6");
break;
case 31:
DispKM("6");
break;
case 32:
DispKM("6");
break;
case 33:
DispKM("6");
break;
case 34:
DispKM("6");
break;
case 35:
DispKM("6");
break;
case 36:
DispKM("6");
break;
case 37:
DispKM("6");
break;
case 38:
DispKM("6");
break;
case 39:
DispKM("6");
break;
case 40:
DispKM("6");
break;
case 41:
DispKM("6");
break;
case 42:
DispKM("6");
break;
case 43:
DispKM("6");
break;
case 50:
dmd.selectFont(Droid_Sans_12);
digitalWrite(10,HIGH);
drawText(".");
delay(500);
digitalWrite(10,LOW);
dmd.clearScreen();
delay(500);
id=0;
dmd.selectFont(Arial_Black_16);
break;
default :
digitalWrite(10,LOW);
}
//mySerial1.flush();
}