Simple Crane Code

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1477
    RC Tractor Guy
    Keymaster

    This is the crane code for cksmaya who is making a simple wooden crane with three movements and a magnet.

    So you are using an Arduino Uno, Joystick shield and NRF24L01 as a controller correct?

    And in the crane you have an Arduino pro mini and an NRF24L01 to receive correct?

    How do you control arm up down, arm lift right turn and load up down? Are they 3 motors or servos? If they are motors are you using a motor driver like TB6612FNG?

    I changed the controller code to this because you don’t need all the functions the original code needed. In this code the joystick y controls up and down and the joystick x controls left and right. Then you push the F button on the joystick shield and now the joystick y contols load up and down. Button A control the solenoid magnet and button C controls some LEDs if you want.

    /*
    Crane Controller Code 
    */
    
    // Define variables
    int Joy_X = 0x00;
    int Joy_Y = 0x00;
    int Joy_X_Old = 0x00;
    int Joy_Y_Old = 0x00;
    int Data_Check_Timer = 0;
    int Active_Vehicle = 0;
    int Num_Vehicle = 1;
    int Controller_Mode = 0;
    int A_Button = LOW;
    int B_Button = LOW;
    int C_Button = LOW;
    int D_Button = LOW;
    int E_Button = LOW;
    int F_Button = LOW;
    int Joy_Button = LOW;
    int X_Hold = 0;
    int Y_Hold = 0;
    
    #include <SPI.h>
    #include "RF24.h"
    
    RF24 radio(9,10);
    
    // Controller Address
    const uint64_t pipe = 0xE8E8F0F0E1LL;
    
    /*-----( Declare Variables )-----*/
    uint8_t command[8];  // 2 element array of unsigned 8-bit type
    
    void setup()
    {
      pinMode(2, INPUT_PULLUP);  // A Button
      pinMode(3, INPUT_PULLUP);  // B Button
      pinMode(4, INPUT_PULLUP);  // C Button 
      pinMode(5, INPUT_PULLUP);  // D Button 
      pinMode(6, INPUT_PULLUP);  // E Button
      pinMode(7, INPUT_PULLUP);  // F Button
      pinMode(8, INPUT_PULLUP);  // Joystick button
    
     radio.begin();
     radio.openWritingPipe(pipe); 
     }
    
    void loop() {
      Check_Buttons();
      Check_Pots();
      Regular_Data_Check();
    }
    
    void Check_Buttons(){
      // Check Joystick Switches
      A_Button = digitalRead(2);
      B_Button = digitalRead(3);
      C_Button = digitalRead(4);
      D_Button = digitalRead(5);
      E_Button = digitalRead(6);
      F_Button = digitalRead(7);
      Joy_Button = digitalRead(8);
    
    if (A_Button==LOW)
      {
        if (command[3] != 1){
          command[3]=1;  // Command to turn on magnet
        }
        else {
          command[3]=0;  // Command to turn off magnet
        }
    
        // Wait for switch to be released
        while (A_Button == LOW)
        {
          A_Button = digitalRead(2);
        }
        Send_Data();
      }
    
    if (C_Button==LOW)
      {
        if (command[4] != 1){
          command[4]=1;  // Command to turn on lights
        }
        else {
          command[4]=0;  // Command to turn off lights    
        }
    
        // Wait for switch to be released
        while (C_Button == LOW)
        {
          C_Button = digitalRead(4);
        }
        Send_Data();
      }
    
      if (B_Button==LOW)
      {
        
        //Add B button code here
    
        // Wait for switch to be released
        while (B_Button == LOW)
        {
          B_Button = digitalRead(3);
        }
        Send_Data();
      }
      
      
      if (D_Button==LOW)
      {
    
        // Add D button code here
        
        // Wait for switch to be released
        while (D_Button == LOW)
        {
          D_Button = digitalRead(5);
        }
        Send_Data();
        
      }
      
      if (E_Button==LOW)  //E button cycles through controller modes
      {
        if(Controller_Mode != 1){
        Controller_Mode = 1;  //Enter mode 1
        }
        else{
        Controller_Mode = 0;  //Enter mode 0
        }
    
        // Wait for switch to be released
        while (E_Button == LOW)
        {
          E_Button = digitalRead(6);
        }
        Send_Data();
      }
      
      if (F_Button==LOW)  //F button cycles through vehicles
      {    
    
        // Add F button code here
        
        // Wait for switch to be released
        while (F_Button == LOW)
        {
          F_Button = digitalRead(7);
        }
        Send_Data();
      }
      
      if (Joy_Button==LOW)
      {
        // Add joystick button code here
    
        // Wait for switch to be released
        while (Joy_Button == LOW)
        {
          Joy_Button = digitalRead(8);
        }
        Send_Data();
      }
      }
    
    void Check_Pots(){
      Joy_X = analogRead(A0);
      Joy_X= map(Joy_X, 0, 1024, 0, 255);
      Joy_Y = analogRead(A1);
      Joy_Y= map(Joy_Y, 0, 1024, 0, 255); 
    
      if(Joy_X != Joy_X_Old || Joy_Y != Joy_Y_Old){
        
        if(Controller_Mode == 0){
          command[0]=Joy_Y;
          command[1]=Joy_X;
           }
        else{
          command[2]=Joy_Y; 
          }
    
        Send_Data();
    
        Joy_X_Old=Joy_X;
        Joy_Y_Old=Joy_Y;
      }
    
    }
    
    // Function to send the data
    void Send_Data(){
      radio.write(command, sizeof(command));
      Data_Check_Timer = 0;  
    }
    
    // Send data in regular intervals to prevent tractor loosing control
    void Regular_Data_Check(){
      Data_Check_Timer=Data_Check_Timer+1;
      if(Data_Check_Timer=1024){
        Send_Data();
      } 
    }

    #1478
    RC Tractor Guy
    Keymaster

    Here is the receive code:

    
    /*
    Crane Reciever Code
    */
    
    // Variables used in the program
    int Motor_1_Speed = 127;
    int Motor_2_Speed = 127;
    int Motor_3_Speed = 127;
    int Magnet_State = 1;
    int LED_State = 0;
    int move1 = 0;
    
    uint8_t buf[8];
    
    #include <SPI.h>
    #include "RF24.h"
    
    RF24 radio(9,10);
    
    // Controller Address
    const uint64_t Controller_1 = 0xE8E8F0F0E1LL;
    
    void setup() 
    {
    
    pinMode(2, OUTPUT); // Motor 1 Direction 1
    pinMode(3, OUTPUT); // Motor 1 PWM
    pinMode(4, OUTPUT); // Motor 1 Direction 2
    pinMode(5, OUTPUT); // Motor 2 PWM
    pinMode(5, OUTPUT); // Motor 3 PWM
    pinMode(7, OUTPUT); // Motor 2 Direction 1
    pinMode(8, OUTPUT); // Motor 2 Direction 2
    pinMode(A0, OUTPUT); // Motor 3 Direction 1
    pinMode(A1, OUTPUT); // Motor 3 Direction 2
    pinMode(A2, OUTPUT); // Magnet Pin
    pinMode(A3, OUTPUT); // LED Pin
    
    radio.begin(); // Initialize the NRF24 Radio Module
    radio.openReadingPipe(1,Controller_1); // Set Address of Controller 1
    radio.startListening(); // Start listening for commands from the controllers
    }
    
    void loop()
    {
    if (radio.available())radio.read(buf, 8);{
    Motor_1_Speed = buf[0];
    Motor_2_Speed = buf[1];
    Motor_3_Speed = buf[2];
    Magnet_State = buf[3];
    LED_State = buf[4];
    
    update_motor(Motor_1_Speed,3,2,4);
    update_motor(Motor_2_Speed,5,7,8);
    update_motor(Motor_3_Speed,6,A0,A1);
    
    //Turn on or off the magnet
    if(Magnet_State==1){
      digitalWrite(A2,HIGH);
    }
    else{
      digitalWrite(A2,LOW);  
    }
    
    //Turn on or off the LEDs
    if(LED_State==1){
      digitalWrite(A3,HIGH);
    }
    else{
      digitalWrite(A3,LOW);
    }
      
    }
    }
    
    void update_motor(int drive_val, int motor_pwm, int motor_dir1, int motor_dir2){
    if (drive_val < 120){ // These if functions leave a buffer zone of 15 bits above and below the drive center value
    move1 = map(drive_val, 120, 0, 0,255);//drive_min, drive_max); // scale the data value for use with the motor
    analogWrite(motor_pwm,move1); // Set the PWM vlue on pin 5 to move the motor
    digitalWrite(motor_dir1, HIGH); // Set the direction with pins 7 and 8
    digitalWrite(motor_dir2, LOW); 
    }
    else if (drive_val > 135){
    move1 = map(drive_val, 135, 255, 0,255);//drive_min, drive_max); // scale the data value for use with the motor 
    analogWrite(motor_pwm,move1); // Set the PWM vlue on pin 5 to move the motor
    digitalWrite(motor_dir2, HIGH); // Set the direction with pins 7 and 8
    digitalWrite(motor_dir1, LOW); 
    
    }
    else{
    move1=0; 
    analogWrite(motor_pwm,move1); // Set the PWM vlue on pin 5 to move the motor
    digitalWrite(motor_dir1, LOW); // Set the direction with pins 7 and 8
    digitalWrite(motor_dir2, LOW);
    }
    
    }
    #1480
    cksmaya
    Participant

    Thank you for your selfless answer for me. I do not know how to thank you.I would like to sponsor your site, you can use VISA card? Thank you help me.
    f I have the ability to say. I think I can add a warning LED lights and a small speaker. Or slowly, step by step to complete. Do not try too much.

    So you are using an Arduino Uno, Joystick shield and NRF24L01 as a controller correct?
    A:Yes, I use Arduino nano control transmitter (Joystick and Button).

    And in the crane you have an Arduino pro mini and an NRF24L01 to receive correct?
    A: I use Arduino nano control receiver (3 servo and 3 limit switch).

    How do you control arm up down, arm lift right turn and load up down? Are they 3 motors or servos? If they are motors are you using a motor driver like TB6612FNG?
    A: I use three servo motor control ARM up down and Arm lift right turn and Load up down. Because this is so can save the motor driver board (L298N) and gearbox motors. Body is relatively small.

    #1481
    cksmaya
    Participant

    Sorry, I change it
    So you are using an Arduino Uno, Joystick shield and NRF24L01 as a controller correct?
    A:Yes, I use Arduino nano control transmitter (3 Joystick and 1 Button).

    #1482
    cksmaya
    Participant

    Supplement my wooden cranes:
    3 joystick control Arm up down amd Arm left right turn and load up down.1 button control electromagnet attract paperclip Press once electromagnet attracted by a solenoid does not attract in. It was so.

    Can I use more than one code . then more a joystick (Joy_Z).control servo .

    
    // Define variables
    int Joy_X = 0x00;
    int Joy_Y = 0x00;
    int joy_z = 0x00;   //////////// I ADD
    int Joy_X_Old = 0x00;
    int Joy_Y_Old = 0x00;
    int Joy_Z_Old = 0x00;//////////// I ADD
    int Data_Check_Timer = 0;
    int Active_Vehicle = 0;
    int Num_Vehicle = 1;
    int Controller_Mode = 0;
    int A_Button = LOW;   
    int B_Button = LOW;
    int C_Button = LOW;
    int D_Button = LOW;
    int E_Button = LOW;
    int F_Button = LOW;
    int Joy_Button = LOW;  //////// I need this control solenoid
    int X_Hold = 0;
    int Y_Hold = 0;
    int Z_Hold = 0;   //////////// I ADD
    
    #1483
    cksmaya
    Participant
    // uint8_t command[8];  // 2 element array of unsigned 8-bit type
    
    uint8_t command[10]; //  This is change
    
    void Check_Pots(){
      Joy_X = analogRead(A0);
      Joy_X= map(Joy_X, 0, 1024, 0, 255);
      Joy_Y = analogRead(A1);
      Joy_Y= map(Joy_Y, 0, 1024, 0, 255); 
      Joy_Z = analogRead(A2);//////////////////////  I add
      Joy_Z= map(Joy_Y, 0, 1024, 0, 255); ////////
    
      if(Joy_X != Joy_X_Old || Joy_Y != Joy_Y_Old  || Joy_Z != Joy_Z_Old){ /////////////////// I add
        
        if(Controller_Mode == 0){
          command[0]=Joy_Y;
          command[1]=Joy_X;
          command[2]=Joy_Z;  ///////// I add
           }
        else{
    //      command[2]=Joy_Y;   ///// I change
          }
    
        Send_Data()
    
        Joy_X_Old=Joy_X;
        Joy_Y_Old=Joy_Y;
        Joy_Z_Old=joy_Z;      ////////////I add
      }
    
    }
    #1484
    cksmaya
    Participant

    This is my code

    
    //YD_nRF24L01_Transmit_JoyStick
    
    /* YourDuinoStarter Example: nRF24L01 Transmit Joystick values
     - WHAT IT DOES: Reads Analog values on A0, A1 and transmits
       them over a nRF24L01 Radio Link to another transceiver.
     - SEE the comments after "//" on each line below
     - CONNECTIONS: nRF24L01 Modules See:
     http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
       1 - GND
       2 - VCC 3.3V !!! NOT 5V
       3 - CE to Arduino pin 9
       4 - CSN to Arduino pin 10
       5 - SCK to Arduino pin 13
       6 - MOSI to Arduino pin 11
       7 - MISO to Arduino pin 12
       8 - UNUSED
       - 
       Analog Joystick or two 10K potentiometers:
       GND to Arduino GND
       VCC to Arduino +5V
       X Pot to Arduino A0
       Y Pot to Arduino A1
       Z Pot to Arduino A2
       Joybutton to Arduino D2
       
     - V1.00 11/26/13
       Based on examples at http://www.bajdi.com/
       Questions: terry@yourduino.com */
    
    /*-----( Import needed libraries )-----*/
    #include <Servo.h> 
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    /*-----( Declare Constants and Pin Numbers )-----*/
    #define CE_PIN   9
    #define CSN_PIN 10
    #define JOYSTICK_X A0
    #define JOYSTICK_Y A1
    #define JOYSTICK_Z A2
    const byte JB = 2;     // 開關的腳位
     boolean b1 = LOW;
    
    // NOTE: the "LL" at the end of the constant is "LongLong" type
    const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
    
    /*-----( Declare objects )-----*/
    RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
    /*-----( Declare Variables )-----*/
    int joystick[4];  // 2 element array holding Joystick readings
    
    void setup()   /****** SETUP: RUNS ONCE ******/
    { 
      pinMode(JB, INPUT);
      digitalWrite(JB,HIGH);
      Serial.begin(9600);
      radio.begin();
      radio.openWritingPipe(pipe);
    }//--(end setup )---
    
    void loop()   /****** LOOP: RUNS CONSTANTLY ******/
    {
     
      b1 = digitalRead(JB);
    
      joystick[0] = analogRead(JOYSTICK_X);
      joystick[1] = analogRead(JOYSTICK_Y);
      joystick[2] = analogRead(JOYSTICK_Y);
      if(b1 == 1){
         joystick[3] = 2;
      }else{
        joystick[3] = 0;
      }
    
         Serial.print(b1);
         Serial.println(joystick[3]);
       
      radio.write( joystick, sizeof(joystick) );
     //Serial.print(joystick[0]);
     //Serial.print(joystick[1]);
     //Serial.print(joystick[2]);
      
    }//--(end main loop )---
    
    /*-----( Declare User-written Functions )-----*/
    
    //NONE
    //*********( THE END )***********
    #1485
    cksmaya
    Participant

    This is my reciever code

    
    //YD_nRF24L01_Receive_JoyStick
    
    /* YourDuinoStarter Example: nRF24L01 Receive Joystick values
    
     - WHAT IT DOES: Receives data from another transceiver with
       2 Analog values from a Joystick or 2 Potentiometers
       Displays received values on Serial Monitor
     - SEE the comments after "//" on each line below
     - CONNECTIONS: nRF24L01 Modules See:
     http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
       1 - GND
       2 - VCC 3.3V !!! NOT 5V
       3 - CE to Arduino pin 9
       4 - CSN to Arduino pin 10
       5 - SCK to Arduino pin 13
       6 - MOSI to Arduino pin 11
       7 - MISO to Arduino pin 12
       8 - UNUSED
       servo Arduino pin
       servoX pin 2
       servoY pin 3
       servoZ pin 4
       
     - V1.00 11/26/13
       Based on examples at http://www.bajdi.com/
       Questions: terry@yourduino.com */
    
    /*-----( Import needed libraries )-----*/
    #include <Servo.h> 
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    /*-----( Declare Constants and Pin Numbers )-----*/
    #define CE_PIN   9
    #define CSN_PIN 10
    
    Servo servoX, servoY, servoZ;
    int posX, posY, posZ;       //設定3個伺服機
    const byte MG = 5;          //電磁鐵輸出接腳
    
    boolean mg = HIGH;           //變數 電磁鐵
    // NOTE: the "LL" at the end of the constant is "LongLong" type
    const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
    
    /*-----( Declare objects )-----*/
    RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
    /*-----( Declare Variables )-----*/
    int joystick[4];  // 2 element array holding Joystick readings 設定3動作1按鈕 資料庫
    
    void setup()   /****** SETUP: RUNS ONCE ******/
    {
      servoX.attach(2);
      servoY.attach(3);
      servoZ.attach(4);
      pinMode(MG,OUTPUT);
      Serial.begin(9600);
      delay(1000);
      Serial.println("Nrf24L01 Receiver Starting");  
      radio.begin();
      radio.openReadingPipe(1,pipe);
      radio.startListening();;
      
    }//--(end setup )---
    
    void loop()   /****** LOOP: RUNS CONSTANTLY ******/
    { 
    
      if ( radio.available() )
      {
        // Read the data payload until we've received everything
        bool done = false;
        while (!done)
        {
          // Fetch the data payload
          done = radio.read( joystick, sizeof(joystick) );
       /*   Serial.print("X = ");
          Serial.print(joystick[0]);
          Serial.print(" Y = ");      
          Serial.println(joystick[1]);
          Serial.print(" Z = ");      
          Serial.println(joystick[2]);*/
          posX = map (joystick[0], 0, 1023, 0, 179);
          posY = map (joystick[1], 0, 1023, 0, 179);
          posZ = map (joystick[2], 0, 1023, 0, 179);
           mg  = joystick[3];
          servoX.write(posX);
          servoY.write(posY);
          servoZ.write(posZ);
     if(mg==0){
      digitalWrite(MG,LOW);     
     }else if(mg==2){
      digitalWrite(MG,HIGH);
     }
     /* switch(mg) {    /////////////按鈕開關程式 電磁鐵
        case '2' :
          digitalWrite(MG,LOW);
          break;
        default :
          digitalWrite(MG,HIGH);
          break;
                 }
       */ 
        Serial.print(" mg = ");      
          Serial.println(joystick[3]);
       }
      }   
      else
      {    
          Serial.println("No radio available");
      }
      
    }//--(end main loop )---
    
    /*-----( Declare User-written Functions )-----*/
    
    //NONE
    //*********( THE END )***********
    #1509
    RC Tractor Guy
    Keymaster

    Sorry for the slow reply, your code looks good to me. Is it working how you want it?

    #1619
    lacoste2500
    Participant

    Hello i’m trayin to build an RC car wthit nrf24 and 2 joystik first one for forward/backward with variable speed pwm and second one for direction .note the car not have a servo motor just 2 CC motor for direction and back/forward ,and i put 2 leds for front lihgt controled by button and 2 leds for stop and 2 leds for turn left and rihgt controled by 2 button left/rihgt and if possible to turn light left and rihgt on same time , so please can You modify the code CarCar 2

    #1620
    lacoste2500
    Participant

    Hello i’m tryin to build an RC car wthit nrf24 and 2 joystik first one for forward/backward with variable speed pwm and second one for direction .note the car not have a servo motor just 2 CC motor for direction and back/forward ,and i put 2 leds for front lihgt controled by button A and 2 leds for stop and 2 leds for turn left and rihgt controled by 2 button B/C left/rihgt and if possible to turn light left and rihgt on the same time , so please can You modify the code for me ,i do it but it have some mistakes ,wen i turn on the lihgt for turning rihgt or left is blinking but wen i try to run it take delay of time to responding the same thing for all the function ,please help

    #1624
    lacoste2500
    Participant

    this the code
    /*
    Crane Reciever Code
    */

    // Variables used in the program
    int Motor_1_Speed = 127;
    int Motor_2_Speed = 127;
    int Motor_3_Speed = 127;
    int Magnet_State = 1;
    int LED_State = 0;
    int move1 = 0;
    int LED2_State = 0;
    int LED3_State = 0;
    int LED4_State = 0;

    uint8_t buf[8];

    #include <SPI.h>
    #include “RF24.h”

    RF24 radio(9,10);

    // Controller Address
    const uint64_t Controller_1 = 0xE8E8F0F0E1LL;

    void setup()
    {

    pinMode(2, OUTPUT); // Motor 1 Direction 1
    pinMode(3, OUTPUT); // Motor 1 PWM
    pinMode(4, OUTPUT); // Motor 1 Direction 2
    pinMode(5, OUTPUT); // Motor 2 PWM
    pinMode(5, OUTPUT); // Motor 3 PWM
    pinMode(7, OUTPUT); // Motor 2 Direction 1
    pinMode(8, OUTPUT); // Motor 2 Direction 2
    pinMode(A0, OUTPUT); // Motor 3 Direction 1
    pinMode(A1, OUTPUT); // Motor 3 Direction 2
    pinMode(A2, OUTPUT); // Magnet Pin
    pinMode(A3, OUTPUT); // LED Pin
    pinMode(A4, OUTPUT); // LED Pin
    pinMode(A5, OUTPUT); // LED Pin
    pinMode(A6, OUTPUT); // LED Pin
    pinMode(A7, OUTPUT); // LED Pin

    radio.begin(); // Initialize the NRF24 Radio Module
    radio.openReadingPipe(1,Controller_1); // Set Address of Controller 1
    radio.startListening(); // Start listening for commands from the controllers
    }

    void loop()
    {
    if (radio.available())radio.read(buf, 8);{
    Motor_1_Speed = buf[0];
    Motor_2_Speed = buf[1];
    Motor_3_Speed = buf[2];
    Magnet_State = buf[3];
    LED_State = buf[4];
    LED2_State = buf[5];
    LED3_State = buf[6];
    LED4_State = buf[7];

    update_motor(Motor_1_Speed,3,2,4);
    update_motor(Motor_2_Speed,5,7,8);
    update_motor(Motor_3_Speed,6,A0,A1);

    //Turn on LIHGT AVANT
    if(Magnet_State==1){
    digitalWrite(A2,HIGH);
    }
    else{
    digitalWrite(A2,LOW);
    }
    //Turn on or OFF LED 2
    if(LED2_State==1){
    digitalWrite(A6,HIGH);
    }
    else{
    digitalWrite(A6,LOW);
    }
    //Turn on or off the magnet
    if(LED3_State==1){
    digitalWrite(A7,HIGH);
    }
    else{
    digitalWrite(A7,LOW);
    }
    //Turn LEFT
    if(LED4_State==1){
    digitalWrite(A5,HIGH);
    delay(500);
    digitalWrite(A5,LOW);
    delay(500);
    }
    //Turn RIHGT
    if(LED3_State==1){
    digitalWrite(A4,HIGH);
    delay(500);
    digitalWrite(A4,LOW);
    delay(500);
    }
    //Turn on REAR LIHGT
    if(LED_State==1){
    digitalWrite(A3,HIGH);
    }
    else{
    digitalWrite(A3,LOW);
    }

    }
    }

    void update_motor(int drive_val, int motor_pwm, int motor_dir1, int motor_dir2){
    if (drive_val < 120){ // These if functions leave a buffer zone of 15 bits above and below the drive center value
    move1 = map(drive_val, 120, 0, 0,255);//drive_min, drive_max); // scale the data value for use with the motor
    analogWrite(motor_pwm,move1); // Set the PWM vlue on pin 5 to move the motor
    digitalWrite(motor_dir1, HIGH); // Set the direction with pins 7 and 8
    digitalWrite(motor_dir2, LOW);
    }
    else if (drive_val > 135){
    move1 = map(drive_val, 135, 255, 0,255);//drive_min, drive_max); // scale the data value for use with the motor
    analogWrite(motor_pwm,move1); // Set the PWM vlue on pin 5 to move the motor
    digitalWrite(motor_dir2, HIGH); // Set the direction with pins 7 and 8
    digitalWrite(motor_dir1, LOW);

    }
    else{
    move1=0;
    analogWrite(motor_pwm,move1); // Set the PWM vlue on pin 5 to move the motor
    digitalWrite(motor_dir1, LOW); // Set the direction with pins 7 and 8
    digitalWrite(motor_dir2, LOW);
    }

    }

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.