daily pastebin goal
85%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int pwm_Master = 11;
  2. int pwm_Center = 6;
  3. int pwm_Wing_Left = 5;
  4. int pwm_Wing_Right = 3;
  5. byte fadeValue = 1;
  6. byte valto_button = 0;
  7. byte buttonPinUp = 12;
  8. byte buttonStateUp = 0;
  9. byte lastbuttonStateUp = 0;
  10. byte buttonPinDown = 13;
  11. byte buttonStateDown = 0;
  12. byte lastbuttonStateDown = 0;
  13. int Value_M = 0;
  14. void setup() {            //ez a rutin egyszer fut le
  15.    
  16.    Serial.begin(9600);
  17.  
  18.     pinMode(buttonPinUp, INPUT); // a gombot bemenetnek inicializáljuk:
  19.     pinMode(buttonPinDown, INPUT);
  20.     pinMode (valto_button, INPUT);
  21.        
  22.     for (fadeValue = 255 ; fadeValue >= 1; fadeValue -= 1) {
  23.     // sets the value (range from 0 to 255):
  24.    
  25.     analogWrite(pwm_Master, fadeValue);
  26.     analogWrite(pwm_Center, fadeValue);
  27.     analogWrite(pwm_Wing_Left, fadeValue);
  28.     analogWrite(pwm_Wing_Right, fadeValue);
  29.     // wait for 30 milliseconds to see the dimming effect
  30.     delay(10);
  31.   }
  32. }
  33.  
  34. /**********************FŐ PROGRAM*****************************************/
  35. void loop() {    
  36.     buttonStateUp = digitalRead(buttonPinUp);                                 // beolvassa a nyomogomb értékeket a megfeleő helyekről
  37.     buttonStateDown = digitalRead(buttonPinDown);
  38.  
  39.     if (buttonStateUp != lastbuttonStateUp) {  // figyeli, hogy állapotváltozás történt-e
  40.         ++ fadeValue;                           // if the current state the button went from off to on:
  41.     }
  42.      if (fadeValue == 255){
  43.             fadeValue -1;
  44.     }              
  45.       delay(10);                                                              // várakozás 150 ms ideig.
  46.  
  47.     if (buttonStateDown != lastbuttonStateDown) {
  48.     // ha állapotváltozás történt  inkrementálja a változót
  49.        -- fadeValue;        
  50.   }
  51.       delay(10);
  52.   valto_button = digitalRead (7);  
  53.  
  54.   if (valto_button == 1)
  55.       Value_M = analogRead (A0);
  56.       else if  (valto_button!=1)
  57.         Value_M = fadeValue * 4;
  58.  
  59.   int Value_C = analogRead(A1);
  60.       if (Value_C > Value_M) {
  61.           Value_C = Value_M;
  62.   }
  63.   int Value_W_L = analogRead(A2);
  64.       if (Value_W_L > Value_M) {
  65.           Value_W_L = Value_M;
  66.   }
  67.   int Value_W_R = analogRead(A3);
  68.       if (Value_W_R > Value_M) {
  69.           Value_W_R = Value_M;
  70.   }
  71.   int voltage_M = (Value_M / 4 );
  72.   int voltage_C = (Value_C / 4);
  73.   int voltage_W_L = (Value_W_L / 4);
  74.   int voltage_W_R = (Value_W_R / 4);
  75. /****************************Debug***************************************/
  76. Serial.print("kapcsoló:");
  77. Serial.print(valto_button);
  78. Serial.print(" ");
  79. Serial.print("Master:");
  80. Serial.print(Value_M/10.23);
  81. Serial.print(" ");
  82. Serial.print("Center:");
  83. Serial.print(Value_C/10.23);
  84. Serial.print(" ");
  85. Serial.print("oldal:");
  86. Serial.print(Value_W_L/10.23);
  87. Serial.print(" ");
  88. Serial.print("oldal:");
  89. Serial.print(Value_W_R/10.23);
  90. Serial.print(" ");
  91. Serial.print("gomb fel,le:");
  92. Serial.println(fadeValue);
  93.  
  94. /*****************************KIIRATÁS************************************/
  95.  
  96.   analogWrite(pwm_Master, voltage_M);
  97.   analogWrite(pwm_Center, voltage_C);
  98.   analogWrite(pwm_Wing_Left, voltage_W_L);
  99.   analogWrite(pwm_Wing_Right, voltage_W_R);
  100.   delay(5);
  101. }
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
 
Top