int buttonModule::readDigital(void){ return digitalRead(pin_number); }
void Digital::digitalToggle(){digitalWrite(!digitalRead());}
void CmdFixture::handle(char * input) { int cntIdx = 0; char cmd = input[1]; char len = input[0]; if (len < 1) return; switch (cmd) { /********** Analog and EEPROM value *******************/ case 0x00: /* get eep voltage min */ cmdRepWord(cmd, eepVoltMin); break; case 0x01: /* get eep voltage max */ cmdRepWord(cmd, eepVoltMax); break; case 0x02: /* get eep current min */ cmdRepWord(cmd, eepCurrMin); break; case 0x03: /* get eep current max */ cmdRepWord(cmd, eepCurrMax); break; case 0x04: /* get AD voltage value */ cmdRepAdVal(cmd, 0); break; case 0x05: /* get AD current value */ cmdRepAdVal(cmd, 1); break; /******************************************************/ /************ Digital monitoring **********************/ case 0x10: /* get Digital 13 (PB5) status */ cmdRepStatus(cmd, digitalRead(StatusOnBoard)); break; case 0x11: /* get Digital 5 (PD5) status */ cmdRepStatus(cmd, digitalRead(StatusPowerDrop)); break; case 0x12: /* get Digital 7 (PD7) status */ cmdRepStatus(cmd, digitalRead(StatusCurrentError)); break; case 0x13: /* get Digital x (Pxx) status */ cmdRepStatus(cmd, digitalRead(StatusPowerOn)); break; case 0x14: /* get Digital 4 (PD4) status */ cmdRepStatus(cmd, digitalRead(OutputReaderPower)); break; case 0x15: /* get Bootloader switch status */ cmdRepStatus(cmd, digitalRead(ButtonBootloader)); break; case 0x16: /* get power switch status */ cmdRepStatus(cmd, digitalRead(ButtonPower)); break; /******************************************************/ /***************** EEPROM setting *********************/ case 0x20: /* set eep voltage min */ if (len == 3) { eepVoltMin = word(input[2], input[3]); writeEepWord(EepAddrVoltMin, eepVoltMin); cmdRepOnly(cmd); } break; case 0x21: /* set eep voltage max */ if (len == 3) { eepVoltMax = word(input[2], input[3]); writeEepWord(EepAddrVoltMax, eepVoltMax); cmdRepOnly(cmd); } break; case 0x22: /* set eep current min */ if (len == 3) { eepCurrMin = word(input[2], input[3]); writeEepWord(EepAddrCurrMin, eepCurrMin); cmdRepOnly(cmd); } break; case 0x23: /* set eep current max */ if (len == 3) { eepCurrMax = word(input[2], input[3]); writeEepWord(EepAddrCurrMax, eepCurrMax); cmdRepOnly(cmd); } break; /******************************************************/ /***************** Digital setting ********************/ case 0x30: /* set Digital 13 (PB5) */ if (len == 2) { digitalWrite(StatusOnBoard, input[2]); cmdRepOnly(cmd); } break; case 0x31: /* set Digital 5 (PD5) */ if (len == 2) { digitalWrite(StatusPowerDrop, input[2]); cmdRepOnly(cmd); } break; case 0x32: /* set Digital 7 (PD7) */ if (len == 2) { digitalWrite(StatusCurrentError, input[2]); cmdRepOnly(cmd); } break; case 0x33: /* set Digital x (Pxx) */ if (len == 2) { digitalWrite(StatusPowerOn, input[2]); cmdRepOnly(cmd); } break; case 0x34: /* set Digital 4 (PD4) */ if (len == 2) { digitalWrite(OutputReaderPower, input[2]); cmdRepOnly(cmd); } break; case 0x35: /* set Digital 2 (PD2): input button */ if (len == 2) { digitalWrite(ButtonBootloader, input[2]); cmdRepOnly(cmd); } break; case 0x36: /* set Digital 3 (PD3): input button */ if (len == 2) { digitalWrite(ButtonPower, input[2]); cmdRepOnly(cmd); } break; /******************************************************/ case 0x80: /* reserved for notify() */ break; case 0x88: /* firmware version */ Serial.print("88"); Serial.println(FirmwareVersion); break; /***************** Error command **********************/ case 0xFE: /* MCU reset */ if (len == 4) { if ((input[2] == 'R') || (input[3] == 'S') || (input[4] == 'T')) { //while(true); /* waiting for watchdog reset */ } } /* no break: it's just fake command */ default: cmdRepOnly(0xFF); break; } }
boolean Reflowster::getButton() { return !digitalRead(pinConfiguration_encoderButton); }
bool waitUntil(int pin, bool pos) { while (digitalRead(pin) != pos); return true; }
main() { struct timespec tp1, tp2; long timp1, timp2, timp3; int i1,i2,x,y; int count; int s1; long double s2; long double accum; long double accum1; struct timespec clock_resolution; int stat; wiringPiSetup () ; pinMode (7, INPUT) ; printf("Start\n"); stat = clock_getres(CLOCK_REALTIME, &clock_resolution); printf("Clock resolution is %d seconds, %ld nanoseconds\n", clock_resolution.tv_sec, clock_resolution.tv_nsec); clock_gettime(CLOCK_REALTIME, &tp1); count=0; while ( count < 200000 ) { while ( digitalRead(7) == LOW ) { } count++; while ( digitalRead(7) == HIGH ) { } count++; } clock_gettime(CLOCK_REALTIME, &tp2); s1 = tp2.tv_sec-tp1.tv_sec; clock_gettime(CLOCK_REALTIME, &tp1); count=0; while ( count < 200000 ) { while ( digitalRead(7) == LOW ) { } count++; while ( digitalRead(7) == HIGH ) { } count++; } clock_gettime(CLOCK_REALTIME, &tp2); s1 = tp2.tv_sec-tp1.tv_sec; s2 = tp2.tv_nsec-tp1.tv_nsec; accum = ( tp2.tv_nsec - tp1.tv_nsec ); accum1= accum; if ( accum<0 ) { accum=accum+1000000000; printf(" acumulator atenuat \n"); } accum1=accum1+s1*1000000000; printf( "ACCUM %lf \n", accum ); printf( "!! ACCUM1 %lf !! \n", accum1); printf(" dif1 calcul scadere secunde %ld \n",s1); printf(" dif2 calcul scadere nanosec %ld \n",s2); printf(" Rez citit secunde %d %d \n",tp1.tv_sec, tp1.tv_nsec); printf(" Rez citit nanosec %ld %lld \n",tp2.tv_sec, tp2.tv_nsec); printf(" Rez calc sec %ld \n",tp2.tv_sec-tp1.tv_sec); printf(" Rez calc nanosec %ld \n",tp2.tv_nsec-tp1.tv_nsec); printf("Stop\n"); }
boolean Reflowster::relayStatus() { return digitalRead(pinConfiguration_relay); }
// Poll for OOK signal bool RFM69OOK::poll() { return digitalRead(_interruptPin); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Function to set Alarm time 1 void set_alarm_1(){ if (digitalRead(button_set_mins_in) == HIGH){ //check minutes button if(alarm_1_time==2400){ alarm_1_time = 0; } alarm_1_time++; //add one minute to offset beep(); Serial.print("Increment alarm minutes "); Serial.print(alarm_1_time); Serial.print("\n"); delay(200); } if (digitalRead(button_set_hrs_in) == HIGH){ //check hours button if(alarm_1_time==2400){ alarm_1_time = 0; } alarm_1_time += 100; //add 60*1 minutes to offset the time beep(); Serial.print("Increment alarm hours "); Serial.print(alarm_1_time); Serial.print("\n"); delay(200); } if(alarm_1_time%100 == 60){ //alarm time is now maybe 1260, but it should not be! alarm_1_time += 40; //alarm time goes to 1300 Serial.print("Alarm 1 time corrected to +40\n"); } if(alarm_1_time > 2359){ //alarm time is now 2401, but it should not be! alarm_1_time = 2400; //alarm time goes to 0000 Serial.print("Alarm 1 time corrected to 0000\n"); } Serial.print("Alarm 1 time: "); Serial.print(alarm_1_time); Serial.print("\n"); gettime(); //Now make the display blink while setting the Alarm 1 time. if((millis_left%1000) > 500){ //0.5 seconds lit up if(alarm_1_time == 2400){ //If alarm is deactivated from user matrix.drawColon(false); matrix.writeDigitRaw(0,B01000000); //"-" matrix.writeDigitRaw(1,B01000000); //"-" matrix.writeDigitRaw(3,B01000000); //"-" matrix.writeDigitRaw(4,B01000000); //"-" matrix.writeDisplay(); } else{ a1h1 = alarm_1_time/1000; a1h2 = ( alarm_1_time - a1h1 * 1000 ) / 100; a1m3 = ( alarm_1_time - a1h1 * 1000 - a1h2 * 100 ) / 10; a1m4 = alarm_1_time % 10; matrix.drawColon(true); matrix.writeDigitNum(0, a1h1); matrix.writeDigitNum(1, a1h2); matrix.writeDigitNum(3, a1m3); matrix.writeDigitNum(4, a1m4); matrix.writeDisplay(); } } else{ matrix.drawColon(false); //0.5 seconds lit off matrix.writeDigitRaw(0,B00000000); //" " matrix.writeDigitRaw(1,B00000000); //" " matrix.writeDigitRaw(3,B00000000); //" " matrix.writeDigitRaw(4,B00000000); //" " matrix.writeDisplay(); } }
/* * The main method initializes the gpios and starts a thread and checks the content * of the files. */ int main() { int res; int count, statusBefore, statusAfter, sensorBefore, sensorAfter; struct timespec sleeptime, result, sensorResult; struct timespec before, measureSensorBefore; struct timespec after, measureSensorAfter; uint16_t distance; sleeptime.tv_sec = 0; sleeptime.tv_nsec = 000010000L; // sleep 10µs int maxPriority; int status; // get max available priority maxPriority = sched_get_priority_max(SCHED_FIFO); if (maxPriority == -1) { perror("Could not determine the maximum priority available."); exit(EXIT_FAILURE); } // set scheduler to SCHED_FIFO and priority to max priority struct sched_param sched; sched.sched_priority = maxPriority; status = sched_setscheduler(0, SCHED_FIFO, &sched); if (status) { perror("ERROR: Could not set real time priority (are you running this as root?)"); exit(EXIT_FAILURE); } // TODO: Add comment for the above sleeptime: How much µs / ms whatever is this? -> use human readable unit here! /*signal(SIGINT, sigfunc); */ wiringPiSetupGpio(); pinMode(GPIO_TRIGGER, OUTPUT); pinMode(GPIO_ECHO, INPUT); statusBefore = clock_gettime(CLOCK_MONOTONIC, &before); digitalWrite(GPIO_TRIGGER, 1); if(clock_nanosleep(CLOCK_MONOTONIC, 0, &sleeptime, NULL)) { perror("nanosleep failed\n"); exit(EXIT_FAILURE); } digitalWrite(GPIO_TRIGGER, 0); while(1) { if(digitalRead(GPIO_ECHO) == 1) { sensorBefore = clock_gettime(CLOCK_MONOTONIC, &measureSensorBefore); break; } } while(1) { if(digitalRead(GPIO_ECHO) == 0) { sensorAfter = clock_gettime(CLOCK_MONOTONIC, &measureSensorAfter); break; } } /* A bit of theory: * Max distance of ultrasonic sensor: about 3m * -> So the max time for the sound to travel to a barrier * and back for this distance is (at 19.2 degree celsius): * 6m / 343m/s = 0.017492711s = 17492711ns * => max number in result.tv_nsec is 17492711ns * * 17492711 * 343 = 5999999873 ==> this is the max number which must be * stored in the meantime during the calculation. * Max no to be stored: 5999999873 * Max no in long : 4294967295 * --> so we need to use an usigned *long long* in the following.. */ sensorResult = diffTime(measureSensorBefore, measureSensorAfter); distance = (uint64_t) sensorResult.tv_nsec * 343 / 1000000 / 2; statusAfter = clock_gettime(CLOCK_MONOTONIC, &after); result = diffTime(before, after); printf("seconds: %ld nanoseconds %ld\n", result.tv_sec, result.tv_nsec); printf("Result: %hu\n\n", distance); delay(20); return(EXIT_SUCCESS); }
int snes_is_on (void) { return digitalRead (PIN_SNES_VCC); }
void *ChangeTHRepresentation (void *param) { (void)param; OCStackResult result = OC_STACK_ERROR; modCounter += 1; if (modCounter % 10 == 0) // Matching the timing that the Linux Sample Server App uses for the same functionality. { byte dht11_dat[5]; byte i;// start condition digitalWrite(dht11_pin, LOW); delay(18); digitalWrite(dht11_pin, HIGH); delayMicroseconds(1); pinMode(dht11_pin, INPUT); delayMicroseconds(40); if (digitalRead(dht11_pin)) { Serial.println("dht11 start condition 1 not met"); // wait for DHT response signal: LOW delay(1000); return NULL; } delayMicroseconds(80); if (!digitalRead(dht11_pin)) { Serial.println("dht11 start condition 2 not met"); //wair for second response signal:HIGH return NULL; } delayMicroseconds(80);// now ready for data reception for (i = 0; i < 5; i++) { dht11_dat[i] = read_dht11_dat(); } //recieved 40 bits data. Details are described in datasheet pinMode(dht11_pin, OUTPUT); digitalWrite(dht11_pin, HIGH); byte dht11_check_sum = dht11_dat[0] + dht11_dat[2]; // check check_sum if (dht11_dat[4] != dht11_check_sum) { Serial.println("DHT11 checksum error"); } Serial.print("Current humdity = "); Serial.print(dht11_dat[0], DEC); Serial.print("% "); Serial.print("temperature = "); Serial.print(dht11_dat[2], DEC); Serial.println("C "); TH.m_humid = dht11_dat[0]; TH.m_temp = dht11_dat[2]; if (g_THUnderObservation) { OC_LOG_V(INFO, TAG, " =====> Notifying stack of new humid level %d\n", TH.m_humid); OC_LOG_V(INFO, TAG, " =====> Notifying stack of new temp level %d\n", TH.m_temp); result = OCNotifyAllObservers (TH.m_handle, OC_NA_QOS); if (OC_STACK_NO_OBSERVERS == result) { g_THUnderObservation = 0; } } } return NULL; }
// Main arduino loop. void loop() { short v; byte t; int p; rov_servo *s; if (!is_waiting && Serial.available() > 32) { Serial.write(OP_SHOULDWAIT); is_waiting = true; return; } else if (is_waiting && Serial.available() < 16) { Serial.write(OP_SHOULDSTART); is_waiting = false; return; } else if (Serial.available() > 0) { switch(Serial.read()) { case OP_SERVO_WRITE: while(!Serial.available()); p = Serial.read(); while(!Serial.available()); v = Serial.read(); if (s = lookup_servo(p)) { // Find the servo object on this pin. s->s.write(v); } break; case OP_DIGITAL_ON: while (!Serial.available()); digitalWrite(Serial.read(),HIGH); break; case OP_DIGITAL_OFF: while (!Serial.available()); digitalWrite(Serial.read(),LOW); break; case OP_DIGITAL_READ: while(!Serial.available()); v = (digitalRead(Serial.read()) == HIGH) ? 1 : 0; Serial.write((uint8_t*) &v,2); break; case OP_ANALOG_WRITE: while (!Serial.available()); p = Serial.read(); while (!Serial.available()); v = Serial.read(); analogWrite(p,v); break; case OP_ANALOG_READ: while (!Serial.available()); v = analogRead(Serial.read()); Serial.write((uint8_t*) &v,2); break; case OP_SET_PINSTATE: while (!Serial.available()); t = Serial.read(); p = t & 0x3f; // Get the pin number. if (s = lookup_servo(p)) { // Detach any servos on this pin. s->s.detach(); s->p = -1; } t = (t & 0xc0) >> 6; if (t == ROV_SERVO) { for (v = 0; v < SERVOC; v++) { if (servov[v].p == -1) { // Find a free servo. s = &servov[v]; s->p = p; s->s.attach(p,1000,2000); s->s.write(90); break; } } } else if (t == INPUT_PULLUP) { pinMode(p,INPUT_PULLUP); } else { pinMode(p,(t) ? OUTPUT : INPUT); } break; } } }
int irModule::readDigital(void){ return digitalRead(orderNumber); }
void cc3k_int_poll() { if (digitalRead(g_irqPin) == LOW && ccspi_is_in_irq == 0 && ccspi_int_enabled != 0) { SPI_IRQ(); } }
void alarm_beep(){ int count0 = 0; do{ count0++; int count = 0; //cut the beep at some point writetime(); drawDots(); delay(20); digitalWrite(led_RGB_1, HIGH); digitalWrite(led_RGB_2, HIGH); if( count0%3 == 0 ){ print_sad(); //Print a sad smile delay(300); } //Serial.print("In alarm - beep \n"); beep(); delay(100); beep(); delay(100); beep(); delay(150); if (digitalRead(alarm_off_1) == HIGH){ //Serial.print("One 1 end touched :) \n"); digitalWrite(led_RGB_1, LOW); print_smile(); delay(500); do{ //Now beep less if(count%5 == 0) { beep(); } count++; writetime(); drawDots(); if (digitalRead(alarm_off_2) == HIGH){ //Alarm off //Serial.print("Other 2 end touched, alarm = 0 \n"); digitalWrite(led_RGB_2, LOW); alarm = 0; break; } //Serial.print("In while loop 1! \n"); delay(100); } while(digitalRead(alarm_wire) == LOW || alarm == 0); delay(100); //Serial.print("While loop exited, now exit alarm \n"); } else if (digitalRead(alarm_off_2) == HIGH){ //Serial.print("One 2 end touched :) \n"); digitalWrite(led_RGB_2, LOW); print_smile(); delay(500); do{ //Now beep less if(count%5 == 0) { beep(); } count++; writetime(); drawDots(); if (digitalRead(alarm_off_1) == HIGH){ //Alarm off //Serial.print("Other 1 end touched, alarm = 0 \n"); digitalWrite(led_RGB_1, LOW); alarm = 0; break; } Serial.print("In while loop 2! \n"); delay(100); } while(digitalRead(alarm_wire) == LOW || alarm == 0); delay(100); //Serial.print("While loop exited, now exit alarm \n"); //exit; } } while( alarm != 0 ); print_smile(); //Show a smile delay(700); print_alarm_off(); //Serial.print("I said!!!!! Exit alarm loop: Alarm = "); //Serial.print(alarm); //Serial.print("\n"); }
int Switch::val () { value = digitalRead (pin); }
void loop() { //Write time Serial.print(" --- Time \n"); writetime(); delay(30); //Draw dots drawDots(); delay(30); //Check whether to go into settings mode if(digitalRead(button_settings_in) == HIGH){ beep(); Serial.print("In settings \n"); settings(); } delay(30); //Now check if we have alarm acivated! gettime(); //Serial.print("Before: Alarm = "); //Serial.print(alarm); //Serial.print("\n"); //delay(30); if( time == alarm_1_time && alarm){ //alarm = 0; alarm_beep(); //Play the beep Serial.print("NO MORE BEEP \n"); delay(500); } else if(time != alarm_1_time) alarm = 1; //Serial.print("After: Alarm = "); //Serial.print(alarm); //Serial.print("\n"); //Serial.print("NO ALARM \n"); //delay(60); //Check brightness if (digitalRead(button_set_mins_in) == HIGH){ //check minutes button brightness++; //increase brightness beep(); if( brightness > 15 ) { brightness = 15; delay(beep_delay); beep(); delay(beep_delay); beep(); } matrix.setBrightness(brightness); Serial.print("Brightness level changed:"); Serial.print(brightness); Serial.print("\n"); delay(150); } if (digitalRead(button_set_hrs_in) == HIGH){ //check hours button brightness--; //decrease brightness beep(); if( brightness < 0 ) { brightness = 0; delay(beep_delay); beep(); delay(beep_delay); beep(); } matrix.setBrightness(brightness); Serial.print("Brightness level changed:"); Serial.print(brightness); Serial.print("\n"); delay(150); } }
void Stage::loop() { //Check for manual commands manualControl(); //Test limit switches to prevent driving stage past limits if(!digitalRead(Z_ULIMIT_SWITCH) && (getDistanceToGo(Z_STEPPER) > 0)){ Move(Z_STEPPER,0); } if(!digitalRead(Z_LLIMIT_SWITCH) && (getDistanceToGo(Z_STEPPER) < 0)){ Move(Z_STEPPER,0);; } //Called on every loop to enable non-blocking control of steppers if((millis()-_z_last_step)>_z_interval){ if((_z_target-_z_pos)>0){ z_1_motor->onestep(FORWARD, DOUBLE); z_2_motor->onestep(FORWARD, DOUBLE); _z_last_step = millis(); _z_pos++; } else if((_z_target-_z_pos)<0){ z_1_motor->onestep(BACKWARD, DOUBLE); z_2_motor->onestep(BACKWARD, DOUBLE); _z_last_step = millis(); _z_pos--; } } if((millis()-_xy_last_step)>_xy_interval){ if((_x_target-_x_pos)>0 && (_y_target-_y_pos)>0){ //Move up and right xy_a_motor->onestep(FORWARD, INTERLEAVE); _xy_last_step = millis(); _x_pos++; _y_pos++; } else if((_x_target-_x_pos)>0 && (_y_target-_y_pos)<0){ //Move down and right xy_b_motor->onestep(FORWARD, INTERLEAVE); _xy_last_step = millis(); _x_pos++; _y_pos--; } else if((_x_target-_x_pos)<0 && (_y_target-_y_pos)>0){ //Move up and left xy_b_motor->onestep(BACKWARD, INTERLEAVE); _xy_last_step = millis(); _x_pos--; _y_pos++; } else if((_x_target-_x_pos)<0 && (_y_target-_y_pos)<0){ //Move down and left xy_a_motor->onestep(BACKWARD, INTERLEAVE); _xy_last_step = millis(); _x_pos--; _y_pos--; } else if((_x_target-_x_pos)==0 && (_y_target-_y_pos)>0){ //Move up xy_a_motor->onestep(FORWARD, INTERLEAVE); xy_b_motor->onestep(BACKWARD, INTERLEAVE); _xy_last_step = millis(); _y_pos++; } else if((_x_target-_x_pos)==0 && (_y_target-_y_pos)<0){ //Move down xy_a_motor->onestep(BACKWARD, INTERLEAVE); xy_b_motor->onestep(FORWARD, INTERLEAVE); _xy_last_step = millis(); _y_pos--; } else if((_x_target-_x_pos)>0 && (_y_target-_y_pos)==0){ //Move right xy_a_motor->onestep(FORWARD, INTERLEAVE); xy_b_motor->onestep(FORWARD, INTERLEAVE); _xy_last_step = millis(); _x_pos++; } else if((_x_target-_x_pos)<0 && (_y_target-_y_pos)==0){ //Move left xy_a_motor->onestep(BACKWARD, INTERLEAVE); xy_b_motor->onestep(BACKWARD, INTERLEAVE); _xy_last_step = millis(); _x_pos--; } } }
void setup(){ Serial.begin(B2_SERIAL0_BOUND); serial0Buffer = ""; Serial.println(""); // remove dust Serial.flush(); // read pcb type pinMode( PIN_B3_POWER_SENSOR, INPUT ); boolean power = digitalRead( PIN_B3_POWER_SENSOR ); if( power == LOW ){ Serial.println("-chyba 2"); }else{ Serial.println("-chyba 3"); } //pcb_type disableYZ(); if(pcb_type == 2 ){ // servos + magicled //pinMode(PIN_B2_SERVO_Y, INPUT+INPUT_PULLUP ); // nie pozwalaj na przypadkowe machanie na starcie //pinMode(PIN_B2_SERVO_Z, INPUT+INPUT_PULLUP ); // nie pozwalaj na przypadkowe machanie na starcie pinMode(PIN_B2_SELF_RESET, INPUT ); pinMode(PIN_B2_HALL_X, INPUT + INPUT_PULLUP ); pinMode(PIN_B2_HALL_Y, INPUT + INPUT_PULLUP ); pinMode(PIN_B2_WEIGHT, INPUT); }else if(pcb_type == 3 ){ // actuators + magicled if(YZ_INPUT_ON_DISABLE){ pinMode(PIN_B3_OUT_Y1, INPUT ); // stop Y pinMode(PIN_B3_OUT_Y2, INPUT ); // stop Y pinMode(PIN_B3_OUT_Z1, INPUT ); // stop Z pinMode(PIN_B3_OUT_Z2, INPUT ); // stop Z }else{ pinMode(PIN_B3_OUT_Y1, OUTPUT); pinMode(PIN_B3_OUT_Y2, OUTPUT); pinMode(PIN_B3_OUT_Z1, OUTPUT); pinMode(PIN_B3_OUT_Z2, OUTPUT); pinMode(PIN_B3_LIGHT, INPUT ); digitalWrite(PIN_B3_OUT_Y1, YZ_VALUE_ON_DISABLE); // stop Y digitalWrite(PIN_B3_OUT_Y2, YZ_VALUE_ON_DISABLE); digitalWrite(PIN_B3_OUT_Z1, YZ_VALUE_ON_DISABLE); // stop Z digitalWrite(PIN_B3_OUT_Z2, YZ_VALUE_ON_DISABLE); } //pinMode(PIN_B3_POWER_SENSOR, INPUT + INPUT_PULLUP ); pinMode(PIN_B3_POWER_SENSOR, INPUT ); } // blink led pinMode(PIN_B2_STEPPER_DIR, OUTPUT ); for(byte i =0; i<pcb_type;i++){ digitalWrite( PIN_B2_STEPPER_DIR, HIGH ); delay(100); digitalWrite( PIN_B2_STEPPER_DIR, LOW ); delay(200); } init_leds(); setupStepper(); unsigned long int color = bottom_panels.Color(0, 0, 20 ); set_all_leds(color); Serial.println(""); // remove dust Serial.flush(); Serial.println("BSTART"); if(pcb_type == 2 ){ // servos + magicled init_hallx(PIN_B2_HALL_X); }else if(pcb_type == 3 ){ init_hallx(PIN_B3_IN_X); } sendStats( true ); Serial.flush(); }
// Buttons ////////// boolean Reflowster::getBackButton() { return !digitalRead(pinConfiguration_backButton); }
void loop() { mil = millis(); /* if( mil > when_next ){ // debug, mrygaj co 1 sek if( bitRead(sending, 0 ) ){ sendVal(0);} if( bitRead(sending, 1 ) ){ sendVal(1);} if( bitRead(sending, 2 ) ){ sendVal(2);} if( bitRead(sending, 3 ) ){ sendVal(3);} if( bitRead(sending, 4 ) ){ sendVal(4);} if( bitRead(sending, 5 ) ){ sendVal(5);} if( bitRead(sending, 6 ) ){ sendVal(6);} if( bitRead(sending, 7 ) ){ sendVal(7);} if( bitRead(sending, 8 ) ){ sendVal(8);} if(sending > 0){ Serial.println(); } when_next = mil + time; }*/ if( pcb_type == 3 && divider-- == 0 ){ boolean power = digitalRead( PIN_B3_POWER_SENSOR ); if( power == LOW ){ low_for_sure++; divider = PWR_SENSOR_DIV/2; // high speed checking if( low_for_sure > 90 ){ Serial.println("F0"); Serial.flush(); } }else{ low_for_sure = 0; divider = PWR_SENSOR_DIV; } } readHall(); step_servoY(); step_servoZ(); if(stepperIsReady){ sendStepperReady(); stepperIsReady = false; } /* if(pre--){ int16_t val1 = analogRead( PIN_B2_WEIGHT ); agv = (val1 + agv * 3)>>2; if( val1 - agv > 2 ){ byte r = abs(val1 - agv); bottom_panels.setPixelColor(0, r,0,0 ); bottom_panels.show(); }else if( val1 - agv < 2 ){ byte g = abs(val1 - agv); bottom_panels.setPixelColor(1, 0,g,0 ); bottom_panels.show(); } }*/ if( mil - last_android > MAX_TIME_WITHOUT_ANDROID ){ // no android last_android = mil; disableServosNow(); stepperX.disableOutputs(); // unsigned long int color = bottom_panels.Color(20, 0, 0 ); // set_all_leds(color); Serial.println("RRNOMASTER"); Serial.flush(); } if( servo_start_time != 0 ){ unsigned long period = millis() - servo_start_time; if( period > SERVO_MAX_TIME ){ // emergency stop disableServosNow(); servo_start_time = 0; unsigned long int color = bottom_panels.Color(255, 0, 0 ); set_all_leds(color); Serial.println("RRSERVOOFF"); Serial.flush(); } } if( mil - last_poke > POKE_ANDROID_TIME ){ // no android Serial.print("POKE "); Serial.println(String(mil)); Serial.flush(); last_poke = mil; } }
void RFStructure::makeFrame(RFModes mode) { if (mode == OfflineMode) { frame.clear(); //don't send anything. return; } RFPacket packet; byte analog[2]; for (byte i = 0; i < 2; i++){ analog[i] = (analogRead(analogPins[i])/10); //read analog pin, reducing to 6bit. Max value will be ~620 due to non rail-rail op-amp. analog[i] &= 0x3F; //6bit analog values sent, so fix to 6 bits. } //PayloadLengths payload =DigitalOnlyPayload;//= payloadLength(mode); frame.payload = 0; switch ((byte)mode) { case DoubleAnalogMode: case DirectionalAnalogMode: case DoubleServoMode: case DirectionalServoMode: frame.payload++; packet.AnalogPacket.clear(); //packet.AnalogPacket.ID = AnalogPacket; packet.AnalogPacket.value = analog[0]; //lower 5 bits get sent in analog packet frame.data[4] = parity(packet); case SingleServoMode: case SingleAnalogMode: frame.payload++; packet.AnalogPacket.clear(); //packet.AnalogPacket.ID = AnalogPacket; packet.AnalogPacket.value = analog[1]; frame.data[3] = parity(packet); case DigitalMode: frame.payload++; packet.DigitalPacket.clear(); //packet.DigitalPacket.ID = DigitalPacket; if(digitalRead(pins[0])&1){ packet.DigitalPacket.d0 = 1; } if(digitalRead(pins[1])&1){ packet.DigitalPacket.d1 = 1; } if(digitalRead(pins[2])&1){ packet.DigitalPacket.d2 = 1; } if(analog[0]&0x20){ packet.DigitalPacket.d3 = 1; //upper most bit gets sent in digital packet. In digitalMode, analogRead>50% will be a digital 1. } if(analog[1]&0x20){ packet.DigitalPacket.d4 = 1; } frame.data[2] = parity(packet); //packet.clear(); packet.HeaderPacket.clear();//.ID = HeaderPacket; packet.HeaderPacket.mode = mode; packet.HeaderPacket.length = frame.payload; frame.data[1] = parity(packet); //packet.clear(); packet.IdentifierPacket.clear();//ID = IdentifierPacket; packet.IdentifierPacket.channel = channel; frame.data[0] = packet; } frame.length = frame.payload + 3; packet.ChecksumPacket.clear(); //packet.ChecksumPacket.ID = ChecksumPacket; packet.ChecksumPacket.checksum = checksum(); frame.data[frame.length-1] = packet; packet.clear(); frame.data[frame.length] = packet; //null termination. }
void Buttons::update(uint8_t *current_state) { /* ---------- UPDATE BUTTONS STATES DEPENDING CENTRAL ARDUINO STATE ---------- */ // Swap only on state change if (*current_state != prev_central_state) { switch(*current_state) { default: case STATE_STARTING_UP: start_led_state = START_LED_ON; start_flashing = true; stop_led_state = STOP_LED_OFF; stop_flashing = false; break; case STATE_RUNNING: start_led_state = START_LED_ON; start_flashing = false; stop_led_state = STOP_LED_OFF; stop_flashing = false; break; case STATE_SHUTTING_DOWN: start_led_state = START_LED_OFF; start_flashing = false; stop_led_state = STOP_LED_ON; stop_flashing = true; break; case STATE_EMERGENCY_STOP: start_led_state = START_LED_ON; start_flashing = false; stop_led_state = STOP_LED_ON; stop_flashing = true; break; case STATE_POWER_DOWN: start_led_state = START_LED_OFF; start_flashing = false; stop_led_state = STOP_LED_OFF; stop_flashing = false; break; } prev_central_state = *current_state; } /* ---------- START LED UPDATE ---------- */ // Update start LED on/off when state changes if (start_led_state != prev_start_led_state) { digitalWrite(START_LED, start_led_state); prev_start_led_state = start_led_state; } if (start_flashing == true) { if (millis() - start_led_current_time >= ((float)1/START_LED_FLASHING_RATE)*1000) { start_led_current_time = millis(); start_led_state = !start_led_state; } } /* ---------- STOP LED UPDATE ---------- */ // Update stop LED on/off when state changes if (stop_led_state != prev_stop_led_state) { digitalWrite(STOP_LED, stop_led_state); prev_stop_led_state = stop_led_state; } // Flash start led @ STOP_LED_FLASHING_RATE times per second if (stop_flashing == true) { if (millis() - stop_led_current_time >= ((float)1/STOP_LED_FLASHING_RATE)*1000) { stop_led_current_time = millis(); stop_led_state = !stop_led_state; } } /* ---------- STOP READ ---------- */ // When stop button is pressed, swap state to shutting down. if (!digitalRead(STOP_READ) == true) { stop_pressed_reset = true; stop_led_state = STOP_LED_ON; // Don't allow basic shutting down until RPi has booted and SPI talking if (*current_state != STATE_STARTING_UP) { if (millis() - stop_hold_time >= STOP_HOLD_TIME) { *current_state = STATE_SHUTTING_DOWN; } } // Hard shutdown if (millis() - stop_hold_time >= STOP_HARD_RESET_TIME) { *current_state = STATE_POWER_DOWN; } } else { if (stop_pressed_reset == true) { stop_led_state = STOP_LED_OFF; stop_pressed_reset = false; } stop_hold_time = millis(); } }
/** * @brief Get interrupt from buttons. All buttons are pulled up by Saeco intelia motherboard. * Consequently, a button press is detected when : * - a falling edge is detected * - after a time t a rising edge is detected * This time t is button press duration. * * Buttons are debounced on coffee machine hardware side with RC filter. But for some buttons (e.g. brew, small cup) * a software handling must be done to identify button press (refer to oscilloscope captures in hardware/scope_capture). * * @param arg_e_buttonId [description] */ static void saecoIntelia_onBtnStateChanged(ECoffeeButtonsId arg_e_buttonId) { if(_u32_buttPress & (1 << arg_e_buttonId)) { /** Error : button press flag has not been handled on application side - reject new press/release */ return; } /** reject it if caused by noise / rebound */ if(!saecoIntelia_checkButtonState(_au8_coffeePins[arg_e_buttonId + NB_COFFEE_BUTTONS])) { return; } if(digitalRead(_au8_coffeePins[arg_e_buttonId + NB_COFFEE_BUTTONS])) { /** button release */ if(_a_li_pressDur[arg_e_buttonId] == 0) { /** Error : button release but did not get button press */ return; } if(millis() - _a_li_pressDur[arg_e_buttonId] < MIN_PRESS_DUR_MS) { /** not a rebound - refer oscilloscope captures (e.g. on brew) In all cases, do not handle this rising edge - wait next rising edge */ return; } if(_apf_buttonPressCbs[arg_e_buttonId]) { /** set flag indicating button has been pressed in order to handle it in a non interrupted context */ _u32_buttPress |= 1 << arg_e_buttonId; _a_li_pressDur[arg_e_buttonId] = millis() - _a_li_pressDur[arg_e_buttonId]; detachInterrupt(_au8_coffeePins[arg_e_buttonId + NB_COFFEE_BUTTONS]); attachInterrupt(_au8_coffeePins[arg_e_buttonId + NB_COFFEE_BUTTONS], _apf_onButtonStateChangedCbs[arg_e_buttonId], FALLING); } else { /** nothing to do - no callback registered */ } } else { /** button press */ /* start press duration meas */ _a_li_pressDur[arg_e_buttonId] = millis(); detachInterrupt(_au8_coffeePins[arg_e_buttonId + NB_COFFEE_BUTTONS]); attachInterrupt(_au8_coffeePins[arg_e_buttonId + NB_COFFEE_BUTTONS], _apf_onButtonStateChangedCbs[arg_e_buttonId], RISING); } }
void loop() { uint8_t new_status; uint8_t tmp; uint8_t tmp_pitch_bit; // // the loop updates the sound parameters // // since we don't want all the parameters updated when playing, // some parameters are updated only on silence and on sustain, // and others are updated only on silence // // envelopes are updated only on silence and sustain if ((g_env_stage != 0) && (g_env_stage != 2)) { g_env_lengths[0] = analogRead(ATTACK_CTRL) * 16; g_env_lengths[1] = analogRead(RELEASE_CTRL) * 16; g_env_type = (digitalRead(LOWPASS_PIN) == LOW) ? 1 : ((digitalRead(FREQ_PIN) == LOW) ? 2 : 0); } // vibrato and resonance are always welcome tmp = (uint8_t)(analogRead(VIBRATO_CTRL) / 4); g_vib_strength = (tmp > 20) ? tmp : 0; tmp = analogRead(RESONANCE_CTRL) / 4; g_lpf_resonance = (tmp > 20) ? tmp : 0; // so are tremolo and distortion g_trem_status = digitalRead(TREM_PIN)==LOW ? 1 : 0; g_dist_status = digitalRead(DIST_PIN)==LOW ? 1 : 0; // // pitch buttons // new_status = get_button_status(); // is the current pitch released? if ((g_env_stage < 2) && ((g_current_pitch_bit & new_status) == 0)) { g_env_stage = 2; } // are all buttons released? if (new_status == 0) { g_current_pitch_bit = 0x00; } // or is a different pitch selected? else if (new_status != g_button_status) { tmp_pitch_bit = g_current_pitch_bit; // if a new button is pressed - select it if (new_status & (~g_button_status)) { tmp_pitch_bit = new_status & (~g_button_status); } // or if the current pitch is released - select another else if ((new_status & (~g_current_pitch_bit)) == 0) { tmp_pitch_bit = new_status; } // select only one pitch tmp_pitch_bit &= (~(tmp_pitch_bit-1)); // if it's really a different pitch, play it if (tmp_pitch_bit != g_current_pitch_bit) { g_current_pitch_bit = tmp_pitch_bit; // change the pitch with interrupts disabled cli(); g_base_freq = get_base_freq(g_current_pitch_bit); reset_sample(); g_env_stage = 0; sei(); } } g_button_status = new_status; }
// Circuit from http://www.electroschematics.com/9964/arduino-water-level-indicator-controller/ bool isWaterFlowing() { return digitalRead(pinWaterPassingSensor) == LOW; }
void Device::loop(){ // temperature sensor #ifdef temperature float umidade = dht.readHumidity(); // Lê o valor da temperatura em Celsius (leitura padrão). float temperatura = dht.readTemperature(); // Calcula o índice de calor em graus Celsius (Fahrenheit = false). float indiceCalor = dht.computeHeatIndex(temperatura, umidade, false); #ifdef LCD ardulcd.loop(umidade,temperatura,indiceCalor); #endif root["temperature"] = temperatura; root["humidity"] = umidade; root["heatIndex"] = indiceCalor; #endif // luminosity sensor #ifdef luminosity int readValue = analogRead(sensorPort); root["luminosity"] = readValue; #ifdef LCD ardulcd.loop(readValue); #endif #endif // presence sensor #ifdef presence //Lendo o valor do sensor PIR. Este sensor pode assumir 2 valores //1 quando detecta algum movimento e 0 quando não detecta. if (detected){ ligarAlarme(); } valorSensorPIR = digitalRead(pinSensorPIR); //Verificando se ocorreu detecção de movimentos if (valorSensorPIR == 1) { root["value'"] = "Tem alguem"; #ifdef LCD ardulcd.loop("Tem alguem"); #endif detected = true; } else { desligarAlarme(); root["value'"] = "Nao tem ninguem"; #ifdef LCD ardulcd.loop("Nao tem ninguem"); #endif detected = false; } #endif // gas sensor #ifdef gas int valor_analogico = 0; valor_analogico = analogRead(sensorPort); root["GasLevel"] = valor_analogico; // Verifica o nível da concentração de gás. if (valor_analogico > nivel_sem_gas){ root["Info"] = "Gas detected."; #ifdef LCD ardulcd.loop("Gas detected", valor_analogico); #endif }else{ root["Info"] = "Gas not detected"; #ifdef LCD ardulcd.loop("Gas not detected", valor_analogico); #endif } #endif #ifdef agua if( digitalRead(sensorPort) == HIGH) { sensorData = 1; root["value"] = "Water detected"; #ifdef LCD ardulcd.loop("Water detected"); #endif }else{ sensorData = 0; root["value"] = "Water undetected"; #ifdef LCD ardulcd.loop("Water undetected"); #endif } if (sensorData == 1){ }else{ } #endif #ifdef USB root.printTo(Serial); #endif }
int Shieldbot::readS1(){ return digitalRead(finder1); }
int microphoneModule::readDigital(void){ return digitalRead(pin_number); }