hi there,
Iam tryig count pulses from arduino on android (in the final it will be flowmeter app)
I press the button on android relay open the circuit and I start count pulses from flowmeter
if I "emulate" pulses via time variable evrything is ok. but when I try real pulses it doesnt count anything
for a firstime I thought, that real one are too fast, but it was no issue (real one was little bit faster then emulated)
any idea why?
thx in advance
#include <Usb.h>
#include <SPI.h>
#include <AndroidAccessory.h>
#define RELE1 4
#define IMPULZ 7
AndroidAccessory acc("MarrekElo", // Manufacturer Name
"AndroidArduinoPHM", // Model Name
"Example sketch for the USB Host Shield", // Description (user-visible string)
"1.0", // Version
"http://www.vesmirni-lide.cz", // URL (web page to visit if no installed apps support the accessory)
"123456789"); // Serial Number (optional)
byte msg[3];
int relatko;
int val;
unsigned long time;
void setup(){
Serial.begin(115200);
pinMode(RELE1, OUTPUT);
pinMode(IMPULZ, INPUT);
acc.powerOn();
}
void loop(){
time = millis();
if(acc.isConnected()){
int len = acc.read(msg,sizeof(msg),1);
if(len > 0){
relatko=msg[0];// i have to use relatko, cos after acc.write is msg array reset to zero
digitalWrite(RELE1,relatko);
acc.write(msg,3);//this one works
}
if(relatko > 0){//relatko is 0/1 toggle button on android side
if(time>0){
msg[1]=time;
acc.write(msg,3);//this one works
}
/*
val = digitalRead(IMPULZ);
if(val>0){
msg[1]=val;
acc.write(msg,3);// this one doesnt
}
*/
}
}
}