Facebook
From Cute Zebra, 3 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 96
  1. #include <iostream>
  2. #include <thread>
  3. #include <unistd.h>
  4. #include <sys/utsname.h>
  5. #include <signal.h>
  6. #include <sys/wait.h>
  7. #include <wiringPi.h>
  8.  
  9.  
  10.  
  11. int arr[3]={0,2,3};
  12.  
  13. void blink1(int *arr);
  14. void blink2(int *arr);
  15. int i = 0;
  16. int main() {
  17.  
  18.  
  19.    wiringPiSetup();
  20.  
  21.  
  22.     for (int m=0;m<3;m++){
  23.        pinMode(arr[m],OUTPUT);
  24.     }
  25.  
  26.     std::thread first(blink1,arr);
  27.     std::thread second(blink2,arr);
  28.  
  29.  
  30.  
  31.     std::cout<<"Prozess ID:"<<getpid()<<" ID Thread First:"<<first.get_id()<<" ID Thread Second:"<<second.get_id()<<std::endl;
  32.  
  33.  
  34.     first.join();
  35.  
  36.     for (int m=0;m<3;m++){
  37.     pinMode(arr[m],0);
  38.     }
  39.  
  40.     std::terminate();
  41.  
  42.  
  43.  
  44.  
  45. }
  46.  
  47.  
  48. void blink1(int *arr){
  49.  
  50.     for(int m = 0; m<5;m++) {
  51.         digitalWrite(arr[i%3],1);
  52.         sleep(1);
  53.         digitalWrite(arr[i%3],0);
  54.         sleep(1);
  55.     }
  56.     std::cout<<"Erster Thread!"<<std::endl;
  57.  
  58. }
  59.  
  60. void blink2(int *arr){
  61.  
  62.     while(1){
  63.         digitalWrite(arr[i%3],1);
  64.         sleep(1);
  65.         digitalWrite(arr[i%3],0);
  66.         sleep(1);
  67.         i++;
  68.     std::cout<<"Zweiter Thread!"<<std::endl;
  69.  
  70.     }
  71. }