hello guys I am final year electrical engineering student
i am working on my FYP and the project i am making is brain controlled wheelchair using neurosky mindwave device as most of u have heard about.Now i have my device connected to MATLAB and in MATLAB i have coded to get the signal of eye blink strength, now i am getting these blink strength value now my other task is to send there values to arduino and i am doing that i am also getting values on arduino but the problem is on arduino i need to count the number of time i blink. before i was controlling the movement of wheelchair on different thresholds like if my blink strength value is between 50 to 75 i go forward if its value is between 75 to 100 i go right u get the point max value is 255 8 bits but what i want is to count number of blinks i do and from those i control my movement i have created the code using timers but it is not working as i wished it would please guide me how i use timers to make this code work or interrupts.Remember the my EGG sensor is connected to matlab. (English is not my strong suite)
int Blinkstrenght;
int count = 0;
const int forward = 13; // these are just leds to imitate the movement right now
const int stopp = 12;//led
const int left = 11;//led
const int right = 10;//led
const unsigned long interval=2000; // the time we need to wait
unsigned long previousMillis=0; // millis()
void setup()
{
Serial.begin(9600);
pinMode(forward, OUTPUT); // declaring outputs
pinMode(stopp, OUTPUT);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT);
}
void loop()
{
if(Serial.available()>0) // here i am getting value from MATLAB
{
Blinkstrenght=Serial.read(); // saving values from 0 to 255 in blinkstrength variable the values depend on how hard i blink or how soft
if (Blinkstrenght > 55 && Blinkstrenght < 100 ) // here i am considering if my blink value is between 55 to 100 i increment the counter to imitate blink counts
{
count = count + 1;
unsigned long currentMillis = millis(); // frm this part i am lost guide me please using timer0 but nothing is working the way i want to
if ((currentMillis - previousMillis) >= interval)
{
while(count){
if (count == 1)
{
digitalWrite(forward, HIGH);
digitalWrite(stopp,LOW);
digitalWrite(left ,HIGH);
digitalWrite(right,LOW);
previousMillis +=interval;
break;
}
if (count ==2)
{
digitalWrite(forward, LOW);
digitalWrite(stopp,LOW);
digitalWrite(left ,LOW);
digitalWrite(right,LOW);
previousMillis +=interval;
break;
}
if (count == 3)
{
digitalWrite(forward, LOW);
digitalWrite(stopp,LOW);
digitalWrite(left ,HIGH);
digitalWrite(right,LOW);
previousMillis +=interval;
break;
}
if (count == 4)
{
digitalWrite(forward, LOW);
digitalWrite(stopp,LOW);
digitalWrite(left ,LOW);
digitalWrite(right,HIGH);
previousMillis +=interval;
break;
}
}
}
}
if ( Blinkstrenght > 100)
{
count = 0;
}
}
}