Exemplo n.º 1
0
void loop() {
    if(stringComplete) {
        // Serial.println(inputString);
        
        if(inputString.equals("{open_valve}")) {
            // Serial.println("inputString equates :)");
            open_valve();
        }
        
        if(inputString.equals("{close_valve}")) {
            // Serial.println("close vavle.");
            close_valve();
        }
        if(valve_open) {
            // Serial.println("valve_open = true");
            inputString = "";
            stringComplete = false;
            while(getFlow4()) {
            }
            // Serial.println("I'm here now :)");
        }
        // clear the string:
        inputString = "";
        stringComplete = false;
    }
    //Serial.println("over and over");
}
Exemplo n.º 2
0
int main(void)
{
    /* Init */
    int pump_timer = 0;
    int i = 0;
    uint16_t tzero = 0;

    DDRD = 0xff;        // initialize port B for output LEDs
    PORTD = 0xff;       // all LEDs initially OFF

    init_timer2();
    initIO();
    sei();
    
    for (int j=0; j < NUM_CYCLES; j++) {

        /* Retain for testing: Use to test delay function */
        //Delay(120);
        //while(1) PORTD=0;
        
        /* Retain for testing: use to cycle pressure read */
        //while(1)
        //read_pressure();
        
        read_pressure();
        close_valve();
        
        tzero = second;   // start time for each section of test
                          // 'second' is a global RTC variable
        
        /*---- Initial pump cycle ----*/
        while ((second - tzero) < PUMP_TIME && pressure < MAX_HI_PRESS) {    

            read_pressure();
            start_pump();
            
            if (pressure > (MAX_HI_PRESS + 200))   // overpressure
                while (error(1));
        }        

        stop_pump();
    
        if (pressure < MAX_HI_PRESS)   // error if target pressure no reached
            while (error(2));

        /*---- Vacuum dwell starts here ----*/
        tzero = second;

        while ((second - tzero) < DWELL_TIME) {

            read_pressure();
            
            if (pressure > (MAX_HI_PRESS + 200))  //overpressure
                while (error(1));

            if (pressure < MIN_HI_PRESS) {

                pump_timer = 0;
                
                while (pressure < MAX_HI_PRESS && ((second - tzero) < DWELL_TIME)) {

                    start_pump();
                    read_pressure();
                    
                    for (i=0; i<1000; i++)    // 1 sec busy-wait 
                        delay_ms(1.0);
                    
                    pump_timer++;
                    
                    if (pump_timer >= 120)    // don't run pump 120 seconds
                        while (error(3));

                    if (pressure > (MAX_HI_PRESS + 200))  //overpressure
                        while (error(1));
                }

                stop_pump();
            }
        }
        
        stop_pump();
        
        /*---- Bleed cycle start ----*/
        open_valve();
        tzero = second;
        
        while ((second - tzero) < BLEED_TIME && pressure > MAX_LO_PRESS)
            read_pressure();

        if (pressure > MAX_LO_PRESS)
            while (error(4));

        /*---- Ambient pressure dwell ----*/
        delay(DWELL_TIME);
    
        //lower = pressure & 0x00ff;
        //upper = (pressure & 0xff00)>>8;
        //PORTD = lower;
    
        //for (i=0; i<1000; i++) _delay_ms(1.0);
    
        //Delay(1);
        //PORTD = upper;
        //for (i=0; i<1000; i++) _delay_ms(1.0);
        //while(1);
    }
    
    while(1)             // completed successfully without errors! 
        error(0);

    return 0;
}