Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. #import <Arduino.h>
  2.  
  3. int motor1_A=3;
  4.  
  5. int motor1_B=5;
  6.  
  7. int motor1_Speed=9;
  8.  
  9. int motor1_C=10;
  10.  
  11. int motor1_D=11;
  12.  
  13.  
  14.  
  15.  
  16.  
  17. void setup(){
  18.  
  19. pinMode(motor1_A,OUTPUT);
  20.  
  21. pinMode(motor1_B,OUTPUT);
  22.  
  23. pinMode(motor1_C,OUTPUT);
  24.  
  25. pinMode(motor1_D,OUTPUT);
  26.  
  27.  
  28.  
  29. }
  30.  
  31.  
  32.  
  33. void loop(){
  34.  
  35. // motor1
  36.  
  37. for (int i=0; i>256; i+=5){
  38.  
  39. digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
  40.  
  41. digitalWrite(motor1_B,LOW);
  42.  
  43. analogWrite(motor1_Speed,i); // speed counts from 0 to 255
  44.  
  45. delay(20);
  46.  
  47. }
  48.  
  49. for (int i=255; i>0; i-=5){
  50.  
  51. digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
  52.  
  53. digitalWrite(motor1_B,LOW);
  54.  
  55. analogWrite(motor1_Speed,i); // speed counts from 0 to 255
  56.  
  57. delay(20);
  58.  
  59. }
  60.  
  61. // motor2
  62.  
  63. for (int i=0; i<256; i+=5){
  64.  
  65. delay(20);
  66.  
  67. }
  68.  
  69. for (int i=255; i>0; i-=5){
  70.  
  71. delay(20);
  72.  
  73. }
  74.  
  75.  
  76.  
  77. // turn vice versa
  78.  
  79.  
  80.  
  81. // motor1
  82.  
  83. for (int i=0; i<256; i+=5){
  84.  
  85. digitalWrite(motor1_A,LOW); // A = LOW and B = HIGH means the motor will turn left
  86.  
  87. digitalWrite(motor1_B,HIGH);
  88.  
  89. analogWrite(motor1_Speed,i); // speed counts from 0 to 255
  90.  
  91. delay(20);
  92.  
  93. }
  94.  
  95. for (int i=255; i>0; i-=5){
  96.  
  97. digitalWrite(motor1_A,LOW); // A = LOW and B = HIGH means the motor will turn left
  98.  
  99. digitalWrite(motor1_B,HIGH);
  100.  
  101. analogWrite(motor1_Speed,i); // speed counts from 0 to 255
  102.  
  103. delay(20);
  104.  
  105. }
  106.  
  107. // motor2
  108.  
  109. for (int i=0; i<256; i+=5){
  110.  
  111. delay(20);
  112.  
  113. }
  114.  
  115. for (int i=255; i>0; i-=5){
  116.  
  117. delay(20);
  118.  
  119. }
  120.  
  121.  
  122.  
  123. // motor1
  124.  
  125. for (int i=0; i>256; i+=5){
  126.  
  127. digitalWrite(motor1_C,HIGH); // C = HIGH and D = LOW means the motor will turn right
  128.  
  129. digitalWrite(motor1_D,LOW);
  130.  
  131. analogWrite(motor1_Speed,i); // speed counts from 0 to 255
  132.  
  133. delay(20);
  134.  
  135. }
  136.  
  137. for (int i=255; i>0; i-=5){
  138.  
  139. digitalWrite(motor1_C,HIGH); // C = HIGH and D = LOW means the motor will turn right
  140.  
  141. digitalWrite(motor1_D,LOW);
  142.  
  143. analogWrite(motor1_Speed,i); // speed counts from 0 to 255
  144.  
  145. delay(20);
  146.  
  147. }
  148.  
  149. // motor2
  150.  
  151. for (int i=0; i<256; i+=5){
  152.  
  153. delay(20);
  154.  
  155. }
  156.  
  157. for (int i=255; i>0; i-=5){
  158.  
  159. delay(20);
  160.  
  161. }
  162.  
  163.  
  164.  
  165. // turn vice versa
  166.  
  167.  
  168.  
  169. // motor1
  170.  
  171. for (int i=0; i<256; i+=5){
  172.  
  173. digitalWrite(motor1_C,LOW); // C = LOW and D = HIGH means the motor will turn left
  174.  
  175. digitalWrite(motor1_D,HIGH);
  176.  
  177. analogWrite(motor1_Speed,i); // speed counts from 0 to 255
  178.  
  179. delay(20);
  180.  
  181. }
  182.  
  183. for (int i=255; i>0; i-=5){
  184.  
  185. digitalWrite(motor1_C,LOW); // C = LOW and D = HIGH means the motor will turn left
  186.  
  187. digitalWrite(motor1_D,HIGH);
  188.  
  189. analogWrite(motor1_Speed,i); // speed counts from 0 to 255
  190.  
  191. delay(20);
  192.  
  193. }
  194.  
  195. // motor2
  196.  
  197. for (int i=0; i<256; i+=5){
  198.  
  199. delay(20);
  200.  
  201. }
  202.  
  203. for (int i=255; i>0; i-=5){
  204.  
  205. delay(20);
  206.  
  207. }
  208. }
  209.  
  210.  
  211.  
  212. #include <Arduino.h>
  213.  
  214.  
  215.  
  216. #ifdef U8X8_HAVE_HW_SPI
  217.  
  218. #include <SPI.h>
  219.  
  220. #endif
  221.  
  222. #ifdef U8X8_HAVE_HW_I2C
  223.  
  224. #include <Wire.h>
  225.  
  226. #endif
  227.  
  228. /*U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=/ SCL, / data=/ SDA, / reset=*/ /*U8X8_PIN_NONE);*/
  229.  
  230.  
  231. byte DZM_InputPin = 2;
  232.  
  233. volatile unsigned long RPM_T2, RPM_Count;
  234.  
  235. unsigned long RPM , RPM_T1;
  236.  
  237.  
  238.  
  239. void setup() {
  240.  
  241. u8g2.begin();
  242.  
  243. pinMode(DZM_InputPin, INPUT_PULLUP);
  244.  
  245. RPM_T1 = 0;
  246.  
  247. RPM_T2 = 0;
  248.  
  249. RPM_Count = 0;
  250.  
  251.  
  252.  
  253. attachInterrupt(0, RPM_Meter, FALLING); // Interrupt0 wird bei fallender Flanke auf Pin2
  254.  
  255.  
  256.  
  257. }
  258.  
  259.  
  260.  
  261. void loop() {
  262.  
  263. char RPMStr[5];
  264.  
  265. u8g2.clearBuffer(); // löschen des Interen Speicher
  266.  
  267. u8g2.setFont(u8g2_font_ncenB14_tr); // auswahl der Schriftart
  268.  
  269. if (RPM_T2 > RPM_T1) {
  270.  
  271. RPM = (unsigned)(long)(60000 * RPM_Count / (RPM_T2 - RPM_T1));
  272.  
  273. RPM_T1 = RPM_T2;
  274.  
  275. RPM_Count = 0;
  276.  
  277. }
  278.  
  279. else {
  280.  
  281. RPM = 0;
  282.  
  283. }
  284.  
  285. sprintf(RPMStr, "%4u", RPM);
  286.  
  287.  
  288.  
  289. u8g2.drawStr(0, 20, RPMStr);
  290.  
  291. u8g2.sendBuffer();
  292.  
  293. }
  294.  
  295.  
  296.  
  297. void RPM_Meter () {
  298.  
  299.  
  300.  
  301. RPM_Count++;
  302.  
  303. RPM_T2 = millis();
  304.  
  305.  
  306.  
  307. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement