Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Arduino.h>
- int motor1_A=3;
- int motor1_B=5;
- int motor1_Speed=9;
- int motor1_C=10;
- int motor1_D=11;
- void setup(){
- pinMode(motor1_A,OUTPUT);
- pinMode(motor1_B,OUTPUT);
- pinMode(motor1_C,OUTPUT);
- pinMode(motor1_D,OUTPUT);
- }
- void loop(){
- // motor1
- for (int i=0; i>256; i+=5){
- digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
- digitalWrite(motor1_B,LOW);
- analogWrite(motor1_Speed,i); // speed counts from 0 to 255
- delay(20);
- }
- for (int i=255; i>0; i-=5){
- digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
- digitalWrite(motor1_B,LOW);
- analogWrite(motor1_Speed,i); // speed counts from 0 to 255
- delay(20);
- }
- // motor2
- for (int i=0; i<256; i+=5){
- delay(20);
- }
- for (int i=255; i>0; i-=5){
- delay(20);
- }
- // turn vice versa
- // motor1
- for (int i=0; i<256; i+=5){
- digitalWrite(motor1_A,LOW); // A = LOW and B = HIGH means the motor will turn left
- digitalWrite(motor1_B,HIGH);
- analogWrite(motor1_Speed,i); // speed counts from 0 to 255
- delay(20);
- }
- for (int i=255; i>0; i-=5){
- digitalWrite(motor1_A,LOW); // A = LOW and B = HIGH means the motor will turn left
- digitalWrite(motor1_B,HIGH);
- analogWrite(motor1_Speed,i); // speed counts from 0 to 255
- delay(20);
- }
- // motor2
- for (int i=0; i<256; i+=5){
- delay(20);
- }
- for (int i=255; i>0; i-=5){
- delay(20);
- }
- // motor1
- for (int i=0; i>256; i+=5){
- digitalWrite(motor1_C,HIGH); // C = HIGH and D = LOW means the motor will turn right
- digitalWrite(motor1_D,LOW);
- analogWrite(motor1_Speed,i); // speed counts from 0 to 255
- delay(20);
- }
- for (int i=255; i>0; i-=5){
- digitalWrite(motor1_C,HIGH); // C = HIGH and D = LOW means the motor will turn right
- digitalWrite(motor1_D,LOW);
- analogWrite(motor1_Speed,i); // speed counts from 0 to 255
- delay(20);
- }
- // motor2
- for (int i=0; i<256; i+=5){
- delay(20);
- }
- for (int i=255; i>0; i-=5){
- delay(20);
- }
- // turn vice versa
- // motor1
- for (int i=0; i<256; i+=5){
- digitalWrite(motor1_C,LOW); // C = LOW and D = HIGH means the motor will turn left
- digitalWrite(motor1_D,HIGH);
- analogWrite(motor1_Speed,i); // speed counts from 0 to 255
- delay(20);
- }
- for (int i=255; i>0; i-=5){
- digitalWrite(motor1_C,LOW); // C = LOW and D = HIGH means the motor will turn left
- digitalWrite(motor1_D,HIGH);
- analogWrite(motor1_Speed,i); // speed counts from 0 to 255
- delay(20);
- }
- // motor2
- for (int i=0; i<256; i+=5){
- delay(20);
- }
- for (int i=255; i>0; i-=5){
- delay(20);
- }
- }
- #include <Arduino.h>
- #ifdef U8X8_HAVE_HW_SPI
- #include <SPI.h>
- #endif
- #ifdef U8X8_HAVE_HW_I2C
- #include <Wire.h>
- #endif
- /*U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=/ SCL, / data=/ SDA, / reset=*/ /*U8X8_PIN_NONE);*/
- byte DZM_InputPin = 2;
- volatile unsigned long RPM_T2, RPM_Count;
- unsigned long RPM , RPM_T1;
- void setup() {
- u8g2.begin();
- pinMode(DZM_InputPin, INPUT_PULLUP);
- RPM_T1 = 0;
- RPM_T2 = 0;
- RPM_Count = 0;
- attachInterrupt(0, RPM_Meter, FALLING); // Interrupt0 wird bei fallender Flanke auf Pin2
- }
- void loop() {
- char RPMStr[5];
- u8g2.clearBuffer(); // löschen des Interen Speicher
- u8g2.setFont(u8g2_font_ncenB14_tr); // auswahl der Schriftart
- if (RPM_T2 > RPM_T1) {
- RPM = (unsigned)(long)(60000 * RPM_Count / (RPM_T2 - RPM_T1));
- RPM_T1 = RPM_T2;
- RPM_Count = 0;
- }
- else {
- RPM = 0;
- }
- sprintf(RPMStr, "%4u", RPM);
- u8g2.drawStr(0, 20, RPMStr);
- u8g2.sendBuffer();
- }
- void RPM_Meter () {
- RPM_Count++;
- RPM_T2 = millis();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement