The controller is an Atmega2560...
#include <TimerOne.h>
#include <Wire.h>
#include <ICSC.h>
bool flag1= false;
bool flag2= false;
bool flag_y = false;
bool flag_n = false;
volatile bool high = false;
volatile bool low = false;
int flash_buffa=0;
int flash_buffb=0;
int phase_buffa=0;
int phase_buffb=0;
byte cleara = B11111111;// COMENZI PE ZERO ....
byte clearb = B11110000;
byte reda = B01101101;// RGVR GVRG
byte redb = B10110000;//VRGV 0000
byte yellow_ona= B10110110;
byte yellow_onb= B11010000;
byte yellow_offa= B11111111;
byte yellow_offb= B11110000;
void setup()
{
Serial.begin(115200);
Wire.begin();
DDRA=B11111111;
DDRF=B11110000;//PF4-7 OUTPUT
DDRD=B00001111;//PD-4-7 INPUTS
DDRC=B00000000;//PC INPUTS
DDRG=0xFF// PG OUTPUTS..LEDURI DE STARE
// =======set I/O pins to outputs
PORTA = cleara; // port A off lights
PORTF = clearb; // port F off lights
//==ICSC set-up ===============================
ICSC.begin(2, 115200,&Serial1,3);
ICSC.registerCommand('G', &Flash_yellow);
ICSC.registerCommand('R', &All_red);
ICSC.registerCommand('D', &Display);
ICSC.registerCommand('O',&Clear);
ICSC.registerCommand('r', &Ready);
//=================pins set-up ====================
digitalWrite(24, HIGH);
//=======timer 1 set-up =============================
Timer1.initialize(480000);
Timer1.attachInterrupt(blinkLED);
Timer1.stop();
}
void loop()
{
ICSC.process();
if(flag_y)
{
Yellow();
}
if(flag_n)
{
Normal_run();
}
}
//===========================================================================
void blinkLED()
{
high=true;
}
//============================================================================
void Clear(unsigned char src, char command, unsigned char len, char *data)
{
flag_y=false;
flag_n=false;
Timer1.stop();
PORTA = cleara; // port A off lights
PORTF = clearb; // port C off lights
}
//===============================================================================
void Flash_yellow(unsigned char src, char command, unsigned char len, char *data)
{
Timer1.start();
flag_y = true;
high=true;
}
//===============================================================================
void All_red(unsigned char src, char command, unsigned char len, char *data)
{
flag_y=false;
flag_n=false;
Timer1.stop();
PORTA = reda; // port A off lights
PORTF = redb; // port C off lights
}
//===============================================================================
void Display(unsigned char src, char command, unsigned char len, char *data)
{
uint16_t *phasea=(uint16_t *)data;
uint16_t *flasha=(uint16_t *)(data+2);
flash_buffa=lowByte(*flasha);
flash_buffb=highByte(*flasha);
phase_buffa=lowByte(*phasea);
phase_buffb=highByte(*phasea);
//buff=(&(*data));
flag_y=false;
flag_n=true;
high=true;
Serial.println(phase_buffa,BIN);
Serial.println(phase_buffb,BIN);
Serial.println(flash_buffa,BIN);
Serial.println(flash_buffb,BIN);
Serial.println(' ');
Timer1.start();
}
//=================================================================================
void Normal_run()
{
if(high)
{
if(!flag2)
{
PORTA=phase_buffa; // port A
PORTF=phase_buffb; // port F
high=false;
flag2=true;
}
else
{
PORTA=flash_buffa; // port A off lights
PORTF=flash_buffb; // port F off lights
flag2=false;
high=false;
}
}
}
//==============================================================================
void Ready(unsigned char src, char command, unsigned char len, char *data)
{
Serial.println(command);
delay(10);
ICSC.send(1,'K',NULL,NULL);
}
//===============================================================================
void Yellow()
{
if(high)
{
if(!flag1)
{
PORTA=yellow_ona; // port A
PORTF=yellow_onb; // port C
flag1=true;
high= false;
}
else
{
PORTA=yellow_offa; // port B
PORTF=yellow_offb; // port B
flag1=false;
high=false;
}
}
}
where could be the error ?
Thanks..