Example #1
0
bool one2two() {
    bool pressed = button_pressed();
    if (pressed) {
        lcd.display();
        led.on();
        lcd.print("Counting!");
    }
    return pressed;
}
Example #2
0
void setup() {
	Serial.begin(9600);
    lcd.begin(16, 2);
    led.on();
	machine.add_transition(0, 1, &button_pressed);
	machine.add_transition(1, 2, &one2two);
	machine.add_transition(2, 0, &button_pressed);
    machine.add_state_function(0, &hello);
    machine.add_state_function(1, &off);
    machine.add_state_function(2, &counting);
}
Example #3
0
int launchChildProcess(int processIndex, ChildProcess *childProcesses, int totalChildProcesses, LED &ledIndicator) {

    int status, waitTimeout = 0;
    pid_t childID, endID;
    time_t when;

    if ((childID = fork()) == -1) { // Start child process.
        perror("fork error");
        exit(EXIT_FAILURE);
    }
    else if (childID == 0) {    // The child process.
        exit(childProcesses[processIndex].func());
    }
    else // The parent process.
    {
        char *descr = childProcesses[processIndex].description;
        time(&when);
        printf("Parent process started at %s", ctime(&when));

        for(;;) { // Wait for child process to terminate.
            endID = waitpid(childID, &status, WNOHANG|WUNTRACED);

            if (endID == -1) // Error calling waitpid.
            {
                perror("waitpid error");
                exit(EXIT_FAILURE);
            }
            else if (endID == 0) // Child still running.
            {
                time(&when);
                printf("Waiting for %s at %s", descr, ctime(&when));
                waitTimeout++ % 2 == 0 ? ledIndicator.on() : ledIndicator.off();
                sleep(1);
            }
            else if (endID == childID) // Child ended.
            {
                if (WIFEXITED(status))
                    printf("%s ended normally. status: %d at %s\n", descr, status, ctime(&when));
                else if (WIFSIGNALED(status))
                    printf("%s ended because of an uncaught signal at %s.\n", descr, ctime(&when));
                else if (WIFSTOPPED(status))
                    printf("%s process has stopped at %s.\n", descr, ctime(&when));
                return status;
            }
        }
    }
    return 1;
}
Example #4
0
// Lower drill, outputs 2sec pulse to lowering pin
void LowerDrill(){
  DrillDown.on();
  timer.setTimeout(2000, StopDrillMove);
}
Example #5
0
// Lift drill, outputs 2sec pulse to lifting pin.
void LiftDrill(){
  DrillUp.on();
  timer.setTimeout(2000, StopDrillMove);
}
Example #6
0
void loop()
{
    if(bNewThrottleSignal0&&bNewThrottleSignal1&&
       1)
    {
        int A= nThrottleIn0;
        Serial.print("0:");
        Serial.print(A);
        Serial.print(" 1:");
        int B= nThrottleIn1;
        Serial.println(B);
        
        
        if(A<1910){
            
            //forward
            if(A<1400 && B>1400 && B<1600){
                P5.writeForward(A);
                P6.writeForward(A);
                P7.writeForward(A);
                P8.writeForward(A);
                
                //  L5.on();
                //  L8.on();
                //  L7.on();
                //  L6.on();
                
                L9.off();
                L10.off();
            }
            //Left
            else if(B<1400){
                P6.writeForward(1300);
                P8.writeForward(1300);
                P5.writeBackward(1700);
                P7.writeBackward(1700);

                L9.on();
                L10.off();
            }

            else if(B>1600){
                P5.writeForward(1300);
                P7.writeForward(1300);
                P6.writeBackward(1700);
                P8.writeBackward(1700);

                L10.on();
                L9.off();
            }

            //turn left
            // else if(B<1400 && A<1400){
            //     int sa = ((A-1400)*(-1))+1600;
            //     P6.writeForward(A);
            //     P8.writeForward(A);
            //     P5.writeBackward(sa);
            //     P7.writeBackward(sa);
                
            //     //  L5.off();
            //     //  L6.on();
            //     //  L7.off();
            //     //  L8.on();
                
            //     L9.on();
            //     L10.off();
            // }
            // //turn right
            // else if(B>1600 && A<1400){
            //     int sa = ((A-1400)*(-1))+1600;
            //     P5.writeForward(A);
            //     P7.writeForward(A);
            //     P6.writeBackward(sa);
            //     P8.writeBackward(sa);
                
            //     //  L5.on();
            //     //  L6.off();
            //     //  L7.on();
            //     //  L8.off();
                
            //     L9.off();
            //     L10.on();
            // }
            //backward
            else if(A>1600 && B>1400 && B<1600){
                P5.writeBackward(A);
                P6.writeBackward(A);
                P7.writeBackward(A);
                P8.writeBackward(A);
                
                //  L5.on();
                //  L6.on();
                //  L7.on();
                //  L8.on();
                
                L9.on();
                L10.on();
            }
            //leftback
            // else if(B<1400 && A>1600){
            //     int sa = 1400 - (A-1600);
            //     P6.writeBackward(A);
            //     P8.writeBackward(A);
            //     P5.writeForward(sa);
            //     P7.writeForward(sa);
                
            //     //  L5.off();
            //     //  L6.on();
            //     //  L7.off();
            //     //  L8.on();
                
            //     L9.off();
            //     L10.on();
            // }
            // //rightback
            // else if(B>1600 && A>1600){
            //     int sa = 1400 - (A-1600);
            //     P5.writeBackward(A);
            //     P7.writeBackward(A);
            //     P6.writeForward(sa);
            //     P8.writeForward(sa);
            //     //  L5.on();
            //     //  L6.off();
            //     //  L7.on();
            //     //  L8.off();
                
            //     L9.on();
            //     L10.off();
            // }
            else{
                L5.off();
                L6.off();
                L7.off();
                L8.off();
                
                L9.off();
                L10.off();
            }
        }

        else if(A>1910){
            L5.off();
            L6.off();
            L7.off();
            L8.off();
            
            L9.off();
            L10.off();
        }
        
        bNewThrottleSignal0 = false;
        bNewThrottleSignal1 = false;
    }
}
Example #7
0
int main()
{
  signal(SIGINT, sig_handler);

  LCD lcd;
  LED led;
  Knob knob;
  Button button;

  int knob_value = 0;
  bool button_value = false;

  char msg[18];
  std::string ip;

  led.on();

  while( (ip = get_ip("wlan0")).length() == 0 )
  {
    lcd.clear();
    lcd.write("looking for IP   ");
    sleep(1);
  }

  led.off();

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write("My IP Address:");
  lcd.setCursor(1, 0);
  lcd.write(ip.c_str());

  sleep(3);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write(ip.c_str());

  while( running == 0 )
  {
    lcd.setCursor(1, 0);
    snprintf(msg, sizeof(msg), "knob: %d%%       ", knob.percent());
    lcd.write(msg);

    if( button.value() )
    {
      led.on();
    }
    else
    {
      led.off();
    }

    if( (button_value != button.value()) || (knob.percent() != knob_value) )
    {
      button_value = button.value();
      knob_value = knob.percent();
   //   post( button_value, knob_value );
    }

    usleep(100000);
  }

  return MRAA_SUCCESS;
}