I have a project to create a tool that can display a warning
This tool uses Arduino duemilove ATMega 328, the sensor matrix ping and RG sparkfun with Backpack
the workings of this tool is to capture objects that have been arranged according to distance and if the object tersebuk into the distance sensor then the device will be issued a warning that output will appearance at the matrix
for sensor I've managed to use but results not yet out of view as scrolling text,
how do I control the order matrix is out with the results of scrolling text?
does anyone have a pattern library symbol to display in the matrix?
I use a 16 matrix ..
this code
#include <EEPROM.h>
#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
#define SENSOR_PIN 7 //Sensor jarak menggunakan ping parallax
#define BLACK 0x00
#define GREEN 0x01
#define RED 0x02
#define ORANGE 0x03
#define WARNA_KOMBINASI_A 0x04
#define WARNA_KOMBINASI_B 0x05
#define MAX_MESSAGE 128 //Jumlah maksimum karakter yang dapat ditampung
#define SCROLL_DELAY 300 //300ms
int warna_led = WARNA_KOMBINASI_A; //simpan warna led dari konfigurasi atau command 'clr'
int sensor_warna_led = RED;
int current_warna_led = GREEN; //warna led untuk di tampilkan di led
int max_sensor_length = 100; //332; //this is maximum PING ultrasonic sensor range 334cm
int min_sensor_length = 2; //this is minimum PING ultrasonic sensor range 2cm
int last_sensor_length;
int sensor_ready = 0;
char default_message [MAX_MESSAGE] = {0};
char sensor_message [MAX_MESSAGE] = {0}; //message untuk ditmpilkan apabila sensor jarak terdeteksi
void showAlphabet(char letter) ;
/* Byte pattern untuk led matrix. Data diambil dari website sparkfun */
byte pattern[] = {
0x18, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00, //0:A
0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C, 0x00, //1:B
0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x3C, 0x00, //2:C
0x78, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0x78, 0x00, //3:D
0x7E, 0x60, 0x60, 0x78, 0x60, 0x60, 0x7E, 0x00, //4:E
0x7E, 0x60, 0x60, 0x78, 0x60, 0x60, 0x60, 0x00, //5:F
0x3C, 0x66, 0xC0, 0xC0, 0xCE, 0x66, 0x3E, 0x00, //6:G
0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, //7:H
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, //8:I
0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, 0x00, //9:J
0x66, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0x66, 0x00, //10:K
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x00, //11:L
0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00, //12:M
0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, //13:N
0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, //14:O
0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, 0x00, //15:P
0x3C, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x0E, 0x00, //16:Q
0x7C, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0x66, 0x00, //17:R
0x3C, 0x66, 0x70, 0x38, 0x0E, 0x66, 0x3C, 0x00, //18:S
0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, //19:T
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3E, 0x00, //20:U
0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, //21:V
0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0xEE, 0xC6, 0x00, //22:W
0x66, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00, //23:X
0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x00, //24:Y
0xFE, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xFE, 0x00, //25:Z
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //SPACE
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, //DOT
};
/* Function transfer data lewat SPI */
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
return SPDR; // return the received byte
}
void setup()
{
int eeprom_index;
//Set mode pin arduino
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT,OUTPUT);
//Setup SPI Bus
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1); //Enable SPI HW, Master Mode, divide clock by 16 //SPI Bus setup
//Matikan led matrix
digitalWrite(CHIPSELECT,HIGH);
delayMicroseconds(500);
/* baca message dari eeprom
- Data yang di set menggunakan command str disimpan dalam eeprom
- agar bila arduino kehilangan power, message yang sudah di set tidak hilang
/
/ mulai baca dari byte 0 - 127 (MAX_MESSAGE)*/
for(eeprom_index=0; eeprom_index<MAX_MESSAGE; eeprom_index++)
{
default_message[eeprom_index] = EEPROM.read(eeprom_index);
}
Serial.print("\r\nset strsensor: ");
Serial.print(val);
Serial.println("\r\n");
}else
{
Serial.println("set string failed\n ");
}
}
else if(strcmp(cmd,"clr") == 0) //cek command ganti color
{
int color;
if(val!=NULL)
{
warna_led = atoi(val);
EEPROM.write((MAX_MESSAGE*2)+1, warna_led );
Serial.print("\r\nset warna: ");
Serial.print(val);
Serial.println("\r\n");
}
}
else if(strcmp(cmd,"clrsensor") == 0) //cek command ganti color
{
int color;
if(val!=NULL)
{
sensor_warna_led = atoi(val);
EEPROM.write((MAX_MESSAGE*2)+2, sensor_warna_led );
Serial.print("\r\nset warna: ");
Serial.print(val);
Serial.println("\r\n");
}
}
else if(strcmp(cmd,"maxsensor") == 0) //cek command ganti color
{
int color;
if(val!=NULL)
{
max_sensor_length = atoi(val);
EEPROM.write((MAX_MESSAGE*2)+3, max_sensor_length );
Serial.print("\r\nset maxsensor: ");
Serial.print(val);
Serial.println("\r\n");
}
}
else if(strcmp(cmd,"minsensor") == 0) //cek command ganti color
{
int color;
if(val!=NULL)
{
min_sensor_length = atoi(val);
EEPROM.write((MAX_MESSAGE*2)+4, min_sensor_length );
Serial.print("\r\nset minsensor: ");