SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int SpwmArry[] =
  2.  {500,500,750,500,1250,500,2000,500,1250,500,750,500,500}; // Array of SPWM values.
  3. const int SpwmArryValues = 13; //Put length of an Array depends on SpwmArray numbers.
  4.  
  5. // Declare the output pins and choose PWM pins only
  6. const int sPWMpin1 = 10;
  7. const int sPWMpin2 = 9;
  8.  
  9. // enabling bool status of Spwm pins
  10. bool sPWMpin1Status = true;
  11. bool sPWMpin2Status = true;
  12.  
  13. void setup(){
  14.   pinMode(sPWMpin1, OUTPUT);
  15.   pinMode(sPWMpin2, OUTPUT);
  16. }
  17.  
  18. void loop(){
  19.  
  20. // Loop for Spwm pin 1
  21. for(int i(0); i != SpwmArryValues; i++)
  22.    {
  23.      if(sPWMpin1Status)
  24.      {
  25.        digitalWrite(sPWMpin1, HIGH);
  26.        delayMicroseconds(SpwmArry[i]);
  27.        sPWMpin1Status = false;
  28.      }
  29.      else
  30.      {
  31.        digitalWrite(sPWMpin1, LOW);
  32.        delayMicroseconds(SpwmArry[i]);
  33.        sPWMpin1Status = true;
  34.      }
  35.    }
  36.  
  37. // Loop for Spwm pin 2
  38. for(int i(0); i != SpwmArryValues; i++)
  39. {
  40.    if(sPWMpin2Status)
  41.    {
  42.      digitalWrite(sPWMpin2, HIGH);
  43.      delayMicroseconds(SpwmArry[i]);
  44.      sPWMpin2Status = false;
  45.    }
  46.    else
  47.    {
  48.     digitalWrite(sPWMpin2, LOW);
  49.     delayMicroseconds(SpwmArry[i]);
  50.     sPWMpin2Status = true;
  51.   }
  52.  }
  53. }
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