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.
Revision 13:ab5d255db0f5, committed 2021-05-14
- Comitter:
- balsijoe
- Date:
- Fri May 14 15:12:27 2021 +0000
- Parent:
- 12:014d7359785d
- Commit message:
- Sensoren Test
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Mar 15 14:05:43 2021 +0000 +++ b/main.cpp Fri May 14 15:12:27 2021 +0000 @@ -13,9 +13,21 @@ void button_fall(); void button_rise(); -/* input your stuff here */ -// Vorlage Lehrer - +//Peripherie +AnalogIn analog_in_A0(PA_0); //FS Futter Behälter Ultraschall +AnalogIn analog_in_A1(PA_1); //FS Wasser Behälter Ultraschall +AnalogIn analog_in_A2(PA_4); //FS Futter Napf Waage +AnalogIn analog_in_A3(PB_0); //FS Wasser Napf Wasserstand +//AnalogOut analog_out_PA_4(PA_4); //Futterausgabe DC-Motor +//AnalogOut analog_out_PA_5(PA_5); //Wasserausgabe Ventil +//DigitalOut Low_Level_PA_6(PA_6); //Warn-LED Füllstand + +float Food_US = 0.0f; +float Water_US = 0.0f; +float Food_Bowl = 0.0f; +float Water_Bowl = 0.0f; +int counter = 0; + int main() { user_button.fall(&button_fall); @@ -29,18 +41,43 @@ /* ------------- start hacking ------------- -------------*/ if(executeMainTask) { - - - - /* visual feedback that the main task is executed */ + //Futterlager + Food_US = analog_in_A0.read(); + //Wasserlager + Water_US = analog_in_A1.read(); + //Futternapf + Food_Bowl = analog_in_A2.read(); + //Wassernapf + Water_Bowl = analog_in_A3.read(); + + //Ausgabe + switch(counter) { + case 1: + printf("Futterlager: %d\r\n", (static_cast<int>(Food_US*100))); + break; + case 2: + printf("Wasserlager: %d\r\n", (static_cast<int>(Water_US*100))); + break; + case 3: + printf("Futterpegel: %d\r\n", (static_cast<int>(Food_Bowl*100))); + break; + case 4: + printf("Wasserpegel: %d\r\n\n\n", (static_cast<int>(Water_Bowl*100))); + break; + case 20: + counter = 0; + break; + default: + break; + } + counter++; + + /* ------------- stop hacking ------------- -------------*/ led = !led; - } else { led = 0; } - - /* ------------- stop hacking ------------- -------------*/ - + int T_loop_ms = duration_cast<milliseconds>(loop_timer.elapsed_time()).count(); int dT_loop_ms = Ts_ms - T_loop_ms; thread_sleep_for(dT_loop_ms);