Advertisement
193030

Vibrating motors logic

Nov 19th, 2020
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int actuators = 6; // 3
  6. int stepsCount = 10; // Tova ne ni trqbva tuk
  7. int stepsDuration = 100;
  8. string input = "101000001110100000111010000011101000001110100000111010000011";
  9.  
  10. int inputConvertedArray[60]; // Int array for the main
  11. int actuatorArrayStep[40];
  12. int currentStep = 0;
  13. int actuatorState;
  14.  
  15. void stringToInt(string inputStr) // String to int array
  16. {
  17.     int inputStringSize = inputStr.length();
  18.     cout << "input string size " << inputStringSize << endl;
  19.     for(int i =0; i<inputStringSize; i++)
  20.     {
  21.         inputConvertedArray[i] = inputStr.at(i)  - 48;
  22.     }
  23.  
  24.     // Print for test
  25.     cout << endl;
  26.     for(int i =0; i<inputStringSize;i++)
  27.     {
  28.         cout << inputConvertedArray[i];
  29.     }
  30.     cout << endl;
  31.  
  32. }
  33.  
  34.  
  35.  
  36. void SetArray()
  37. {
  38.     for(int i =0; i<actuators;i++)
  39.     {
  40.      actuatorArrayStep[i] = stepsCount*i; // 1
  41.     }
  42. }
  43. /* void TurnActuator(int actuator, int state)
  44. {
  45.     //digitalWrite(actuator, state);
  46. }
  47. */
  48. int main()
  49. {
  50.    SetArray();
  51.    stringToInt(input);
  52.  
  53.    for(int k = 0; k<stepsCount; k++)
  54.    {
  55.        cout << "LOOP CYCLE: " << k << endl;
  56.         for(int i =0; i<actuators; i++)
  57.         {
  58.             int currentTempState = actuatorArrayStep[i] + currentStep;
  59.             actuatorState = inputConvertedArray[currentTempState];
  60.         //  TurnActuator(i, actuatorState);
  61.             if(actuatorState == 1)
  62.                 cout << "motor: " << i <<"  true \n";
  63.             else
  64.                 cout << "motor: " << i <<" false \n";
  65.         }
  66.         currentStep++;
  67.    }
  68.  
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement