myeerste

Dependencies:   mbed

main.cpp

Committer:
erastus
Date:
2015-02-06
Revision:
2:36d2742dc2bf
Parent:
1:497211807af7
Child:
3:2e7c3a890019

File content as of revision 2:36d2742dc2bf:

#include "mbed.h"
#ifdef TARGET_UBLOX_C027
 #include "C027_api.h"
#else
 #error "This example is targeted for the C027 platform"
#endif

#define Generator = p36;
//ifdef = 
// PortIn     p(Port2, 0x0000003F);   // p21-p26

void  digitalout( int Status)
  {
}

float AnalogIn ( int BattV)
    {
    float V;
    
    return (V);
    }
       
int main() {
    int PowerI, LoopCounterI, PowerStatusI, Invertor1I, Invertor2I, Invertor3I, Invertor4I;
    int EnableInvertorsI, NoStartI, GenStatusI, LedI, GenOn, GenOff;
    float   BattVoltageF;
    
    PowerI = 0;
    EnableInvertorsI = LoopCounterI = 0;
    GenStatusI = PowerStatusI = NoStartI = 0;
    Invertor1I = Invertor2I = Invertor3I = Invertor4I = 0;
    //  sms ( "Startup");
  //      DigitalOut( P3, 0xff)                           // set all relays off
    while(1) 
        {
        PowerStatusI = DigitalIn( P2_0);            // get main power status
        if ( PowerStatusI )
            if ( GenStatusI)
            {
            if ( LoopCounterI++ > 6000)             // If power is off for 10 minutes
                {
                //  sms( poweroff);
                wait( 300);
                // sms ( starting gen);
                do
                    {
                    LedI = !LedI;
//                    myled( LedI );                   // Toggle LED
                    if ( !GenStatusI )               // If no generator Voltage
                        digitalout( 0);          //  Start Generator
                    wait( 100);
                    GenStatusI = DigitalIn( P2_1);
                    if( GenStatusI)                  //  check for generator Voltage = 220V
                        {
                        digitalout( GenOff);         // stop starting generator
                        // sms( GenOn);
                        }  else
                        if ( NoStartI ++ > 30)       //  try for 3 seconds
                            {
                            // sms( genrator not started);
                            do
                                {
                                digitalout( GenOff);    // Set Generator off
                                wait ( 400);           // Wait for 2 seconds
                                GenStatusI = DigitalIn( P2_1);
                                if ( GenStatusI )
                                    NoStartI = 0;
                                } while ( NoStartI-- > 0);
                            
                            }
                    } while ( GenStatusI == 0);
                digitalout( GenOff);            // set start to off
                //     sms( GenStarted);
                if ( GenStatusI)                // if Gen on close relays
                    {
                    //   sms( "starting inv 1");
 //                   myled( myled);              //  set LED on
                    digitalout ( 1 );        //  start invertor 1
                    wait ( 500);
                    //   sms( "Starting inv 2");
                    digitalout( 2);         //  start invertor 2
                    wait ( 500);
                    //   sms( "Starting inv 3");
                    digitalout( 3 );          //  start invertor 3
                    wait ( 500);
                    //   sms( "Starting inv 4");
                    digitalout( 4 );         //  start invertor 4
                    wait ( 500);
                    //   sms( "Starting Aircon");
                    digitalout( 5 );         //  start aircon
                    }
                }
            } else if ( GenStatusI)
                {
                if ( -- LoopCounterI <= 0)
                    {
                    //   sms( "Eskom On ");
                    //   sms( "Aircon to Eskom");
                    digitalout( 0 );         //  start aircon
                    wait ( 5000);
                    //   sms( "Invertor 1 to Eskom");
//                    myled( myled);              //  set LED on
                    digitalout ( 1 );        //  start invertor 1
                    wait ( 1000);
                    //   sms( "Invertor 2 to Eskom");
                    digitalout( 2 );         //  start invertor 2
                    wait ( 1000);
                    //   sms( "Invertor 3 to Eskom");
                    digitalout( 3 );          //  start invertor 3
                    wait ( 1000);
                    //   sms( "Invertoer 4 to Eskom");
                    digitalout( 4 );         //  start invertor 4                        
                    }  else
                         LoopCounterI = 0;
            } else
                {
//                BattVoltageF =  AnalogIn( 1);    // Batt V
                BattVoltageF *= 0.1039;
                if ( BattVoltageF < 24.00)
                    {
                    // sms( Voltage low);
                    }
                }
//        myled = !myled;
        wait(1000);  // wait 1 sec
//        myled( LedI);
    }   // main loop while