Compare commits
3 commits
main
...
Potentiome
Author | SHA1 | Date | |
---|---|---|---|
boutrie.eytan | addd364b61 | ||
boutrie.eytan | f99cb0c0bb | ||
boutrie.eytan | 3b23142fc1 |
104
Rotabator.ino
104
Rotabator.ino
|
@ -1,77 +1,49 @@
|
||||||
/*
|
const int stepPin = 14;
|
||||||
* Library: https://github.com/bolderflight/MPU9250
|
|
||||||
Basic_I2C.ino
|
|
||||||
Brian R Taylor
|
|
||||||
brian.taylor@bolderflight.com
|
|
||||||
|
|
||||||
Copyright (c) 2017 Bolder Flight Systems
|
const int dirPin = 12;
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
int customDelay,customDelayMapped; // Defines variables
|
||||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
||||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
||||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
||||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
||||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Updated by Ahmad Shamshiri on July 09, 2018 for Robojax.com
|
|
||||||
* in Ajax, Ontario, Canada
|
|
||||||
* watch instrucion video for this code:
|
|
||||||
For this sketch you need to connect:
|
|
||||||
VCC to 5V and GND to GND of Arduino
|
|
||||||
SDA to A4 and SCL to A5
|
|
||||||
|
|
||||||
S20A is 3.3V voltage regulator MIC5205-3.3BM5
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "MPU9250.h"
|
|
||||||
|
|
||||||
float biai = 1.25;
|
|
||||||
unsigned long previousTime;
|
|
||||||
int interval = 300;
|
|
||||||
int stepPin = 14;
|
|
||||||
int dirPin = 12;
|
|
||||||
bool pinState = LOW;
|
|
||||||
// an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
|
|
||||||
MPU9250 IMU(Wire,0x68);
|
|
||||||
int status;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// serial to display data
|
|
||||||
Serial.begin(115200);
|
|
||||||
while(!Serial) {}
|
|
||||||
|
|
||||||
// start communication with IMU
|
// Sets the two pins as Outputs
|
||||||
status = IMU.begin();
|
|
||||||
if (status < 0) {
|
Serial.begin(115200);
|
||||||
Serial.println("IMU initialization unsuccessful");
|
|
||||||
Serial.println("Check IMU wiring or try cycling power");
|
|
||||||
Serial.print("Status: ");
|
|
||||||
Serial.println(status);
|
|
||||||
while(1) {}
|
|
||||||
}
|
|
||||||
pinMode(stepPin,OUTPUT);
|
pinMode(stepPin,OUTPUT);
|
||||||
|
|
||||||
pinMode(dirPin,OUTPUT);
|
pinMode(dirPin,OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// read the sensor
|
|
||||||
digitalWrite(dirPin,HIGH);
|
|
||||||
IMU.readSensor();
|
|
||||||
// display the data
|
|
||||||
|
|
||||||
if((micros() - previousTime) >= interval){
|
|
||||||
previousTime = micros();
|
|
||||||
pinState = !pinState;
|
customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
|
||||||
digitalWrite(stepPin,pinState);
|
// Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
|
||||||
Serial.println(IMU.getAccelX_mss() + IMU.getAccelY_mss() + IMU.getAccelZ_mss() + biai +11);
|
|
||||||
}
|
digitalWrite(stepPin, HIGH);
|
||||||
}
|
|
||||||
|
delayMicroseconds(customDelayMapped);
|
||||||
|
|
||||||
|
digitalWrite(stepPin, LOW);
|
||||||
|
|
||||||
|
delayMicroseconds(customDelayMapped);
|
||||||
|
|
||||||
|
Serial.println(customDelayMapped);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function for reading the Potentiometer
|
||||||
|
|
||||||
|
int speedUp() {
|
||||||
|
|
||||||
|
int customDelay = analogRead(6); // Reads the potentiometer
|
||||||
|
int newCustom = map(customDelay, 0, 8191, 300,3000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
|
||||||
|
|
||||||
|
return newCustom;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue