SHARE
TWEET

APPS #1

a guest Sep 17th, 2019 141 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // **************************************************************************
  2. //
  3. //               Demo program for labs
  4. //
  5. // Subject:      Computer Architectures and Parallel systems
  6. // Author:       Petr Olivka, petr.olivka@vsb.cz, 09/2019
  7. // Organization: Department of Computer Science, FEECS,
  8. //               VSB-Technical University of Ostrava, CZ
  9. //
  10. // File:         Demo program
  11. //
  12. // **************************************************************************
  13.  
  14. #include "mbed.h"
  15.  
  16. void demo_leds();
  17. void demo_lcd();
  18. void demo_i2c();
  19.  
  20. // DO NOT REMOVE OR RENAME FOLLOWING GLOBAL VARIABLES!!
  21.  
  22. // Serial line for printf output
  23. Serial g_pc(USBTX, USBRX);
  24.  
  25. // LEDs on K64F-KIT - instances of class DigitalOut
  26. DigitalOut g_led1(PTA1);
  27. DigitalOut g_led2(PTA2);
  28.  
  29. // Buttons on K64F-KIT - instances of class DigitalIn
  30. DigitalIn g_but9(PTC9);
  31. DigitalIn g_but10(PTC10);
  32. DigitalIn g_but11(PTC11);
  33. DigitalIn g_but12(PTC12);
  34.  
  35. int btn9_Counter = 0;
  36. int ledCounter;
  37. int ledBlink = 1000;
  38.  
  39. int main()
  40. {
  41.     // Serial line initialization
  42.     g_pc.baud(115200);
  43.  
  44.     // uncomment selected demo
  45.     //demo_leds();
  46.     //demo_lcd();
  47.     //demo_i2c();
  48.  
  49.     g_pc.printf( "Demo program started...\r\n" );
  50.  
  51.     // ******************************************************************
  52.  
  53.     // default demo for 2 LEDs and 4 buttons
  54.  
  55.     //int arr[8] = {PTC0, PTC1, PTC2, PTC3, PTC4, PTC5, PTC6, PTC7};
  56.  
  57.     while (1)
  58.     {
  59.         ledCounter = (ledCounter + 1) % 1000000;
  60.         g_led2 = !g_led1;       // inverse blinking
  61.  
  62.         wait_ms(1000);
  63.  
  64.         if (ledCounter % ledCounter == 0){
  65.             g_led1 = !g_led1;
  66.         }
  67.  
  68.         if (g_but9 == 0)
  69.         {
  70.             btn9_Counter++;
  71.             if (btn9_Counter < 1000){
  72.                 ledBlink /= 2;
  73.             }
  74.         }
  75.         else{
  76.             g_led2 = 0;
  77.             btn9_Counter = 0;
  78.         }
  79.  
  80.         while (!g_but9 || !g_but10 || !g_but11 || !g_but12); // stop blinking
  81.     }
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top