Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 //#ifdef TARGET_UBLOX_C027 00003 #include "C027_api.h" 00004 //#else 00005 //#error "This example is targeted for the C027 platform" 00006 //#endif 00007 00008 #include "gpio_api.h" 00009 00010 Serial pc(USBTX, USBRX); // tx, rx 00011 00012 DigitalOut myled (LED); 00013 00014 #define Generator = p36; 00015 //ifdef = 00016 // PortIn p(Port2, 0x0000003F); // p21-p26 00017 00018 void digitalout( int Status) 00019 { 00020 } 00021 00022 float AnalogIn ( int BattV) 00023 { 00024 float V; 00025 00026 return (V); 00027 } 00028 00029 int main() 00030 { 00031 int PowerI, LoopCounterI, PowerStatusI, Invertor1I, Invertor2I, Invertor3I, Invertor4I; 00032 int EnableInvertorsI, NoStartI, GenStatusI, LedI, GenOn, GenOff; 00033 float BattVoltageF; 00034 00035 PowerI = 0; 00036 EnableInvertorsI = LoopCounterI = 0; 00037 GenStatusI = PowerStatusI = NoStartI = 0; 00038 Invertor1I = Invertor2I = Invertor3I = Invertor4I = 0; 00039 uint32_t gpio_set(PinName pin); 00040 for(;;) 00041 pc.printf("Hello World!\n"); 00042 // sms ( "Startup"); 00043 // DigitalOut( LED); // set all relays off 00044 while(1) { 00045 PowerStatusI = DigitalIn( P2_0); // get main power status 00046 if ( PowerStatusI ) 00047 if ( GenStatusI) { 00048 if ( LoopCounterI++ > 6000) { // If power is off for 10 minutes 00049 // sms( poweroff); 00050 wait( 300); 00051 // sms ( starting gen); 00052 do { 00053 LedI = !LedI; 00054 // myled( LedI ); // Toggle LED 00055 if ( !GenStatusI ) // If no generator Voltage 00056 digitalout( 0); // Start Generator 00057 wait( 100); 00058 GenStatusI = DigitalIn( P2_1); 00059 if( GenStatusI) { // check for generator Voltage = 220V 00060 digitalout( GenOff); // stop starting generator 00061 // sms( GenOn); 00062 } else if ( NoStartI ++ > 30) { // try for 3 seconds 00063 // sms( genrator not started); 00064 do { 00065 digitalout( GenOff); // Set Generator off 00066 wait ( 400); // Wait for 2 seconds 00067 GenStatusI = DigitalIn( P2_1); 00068 if ( GenStatusI ) 00069 NoStartI = 0; 00070 } while ( NoStartI-- > 0); 00071 00072 } 00073 } while ( GenStatusI == 0); 00074 digitalout( GenOff); // set start to off 00075 // sms( GenStarted); 00076 if ( GenStatusI) { // if Gen on close relays 00077 // sms( "starting inv 1"); 00078 // myled( myled); // set LED on 00079 digitalout ( 1 ); // start invertor 1 00080 wait ( 500); 00081 // sms( "Starting inv 2"); 00082 digitalout( 2); // start invertor 2 00083 wait ( 500); 00084 // sms( "Starting inv 3"); 00085 digitalout( 3 ); // start invertor 3 00086 wait ( 500); 00087 // sms( "Starting inv 4"); 00088 digitalout( 4 ); // start invertor 4 00089 wait ( 500); 00090 // sms( "Starting Aircon"); 00091 digitalout( 5 ); // start aircon 00092 } 00093 } 00094 } else if ( GenStatusI) { 00095 if ( -- LoopCounterI <= 0) { 00096 // sms( "Eskom On "); 00097 // sms( "Aircon to Eskom"); 00098 digitalout( 0 ); // start aircon 00099 wait ( 5000); 00100 // sms( "Invertor 1 to Eskom"); 00101 // myled( myled); // set LED on 00102 digitalout ( 1 ); // start invertor 1 00103 wait ( 1000); 00104 // sms( "Invertor 2 to Eskom"); 00105 digitalout( 2 ); // start invertor 2 00106 wait ( 1000); 00107 // sms( "Invertor 3 to Eskom"); 00108 digitalout( 3 ); // start invertor 3 00109 wait ( 1000); 00110 // sms( "Invertoer 4 to Eskom"); 00111 digitalout( 4 ); // start invertor 4 00112 } else 00113 LoopCounterI = 0; 00114 } else { 00115 // BattVoltageF = AnalogIn( 1); // Batt V 00116 BattVoltageF *= 0.1039; 00117 if ( BattVoltageF < 24.00) { 00118 // sms( Voltage low); 00119 } 00120 } 00121 // myled = !myled; 00122 wait(1000); // wait 1 sec 00123 // myled( LedI); 00124 } // main loop while 00125 }
Generated on Tue Jul 19 2022 10:19:59 by
1.7.2