void main() { t_firmata *firmata; firmata = firmata_new("/dev/ttyACM99"); //init Firmata while(!firmata->isReady) //Wait until device is up firmata_pull(firmata); firmata_pinMode(firmata, 12, MODE_INPUT); //set pin 3 (led on most arduino) to out float buffer[10]; long int i=0; for (i=0;i<10;i++) { buffer[i]=0; } long int stime=clock(); firmata_pull(firmata); bool value1=firmata->pins[12].value == HIGH; speed=0.0; while (i<9) { firmata_pull(firmata); if((firmata->pins[12].value == HIGH)^(value1)) { buffer[i+1]=clock()-stime; speed = PI*DIAMETER/(4.0*(buffer[i+1]-buffer[i]))*CLOCKS_PER_SEC; } } int j=0; long int etime=0; while (1) { firmata_pull(firmata); if((firmata->pins[12].value == HIGH)^(value1)) { ++i; etime=clock(); if( float(1.0*(etime-stime)/CLOCKS_PER_SEC>SLOW) { speed = PI*DIAMETER/(4.0*(etime-buffer[j==0? 9:j-1]))*CLOCKS_PER_SEC; buffer[j]=etime; j=j==9? 0:j+1; } else if ( float(1.0*(etime-stime)/CLOCKS_PER_SEC>FAST))
int init(void){ int i; if(parse_ini_file(arg_ini) == -1){ return -1; } firmata = firmata_new(serial_port); //init Firmata if (firmata == NULL){ return -1; } while(!firmata->isReady) //Wait until device is up firmata_pull(firmata); firmata_pinMode(firmata, ledg, MODE_OUTPUT); firmata_pinMode(firmata, ledb, MODE_OUTPUT); firmata_pinMode(firmata, ledr, MODE_OUTPUT); for(i=0; i<NUM_REL; i++) { firmata_pinMode(firmata, rel[i], MODE_OUTPUT); firmata_digitalWrite(firmata, rel[i], inv[i]); } return 0; }
int main() { t_firmata *firmata; firmata = firmata_new("/dev/ttyACM99"); //init Firmata while(!firmata->isReady) //Wait until device is up firmata_pull(firmata); firmata_pinMode(firmata, 12, MODE_INPUT); //set pin 3 (led on most arduino) to out while (1) { firmata_pull(firmata); printf("pin 12 value = %d\n", (firmata->pins[12].value == HIGH)); } }
void encoder_updated::initialize() { firmata1 = firmata_new("/dev/ttyACM99"); //init Firmata while(!firmata1->isReady) firmata_pull(firmata1); firmata_pinMode(firmata1, pin, MODE_INPUT);//set pin 3 for (i=0;i<10;i++) { buffer[i]=0; } bool value1=firmata1->pins[12].value == HIGH; speed=0.0; }
int main() { t_firmata *firmata; float val; firmata = firmata_new("/dev/ttyACM99"); //init Firmata while(!firmata->isReady) //Wait until device is up firmata_pull(firmata); firmata_pinMode(firmata, 14, MODE_ANALOG); //set pin 3 (led on most arduino) to out while (1) { firmata_pull(firmata); val = firmata->pins[14].value / 1024.f; printf("pin 14 value = %f\n", val); } }
t_servo *servo_attach(t_firmata *firmata, int pin) { t_servo *res; if (!firmata || !firmata->isReady) { perror("servo_new::Firmata is not ready"); return (NULL); } res = malloc(sizeof(t_servo)); if (!res) { perror("servo_new::malloc failed"); return (NULL); } res->firmata = firmata; res->pin = pin; firmata_pinMode(res->firmata, pin, MODE_SERVO); return (res); }