So basically what the title says is my problem, I have a standby phase of the loop before the “if” statement. I want to hold down triggerButton1 to increment and loop the stepper.setSpeed, in turn accelerating the stepper to a limited speed. But I have warnings telling me…(see picture)
To give some insight of my project after that point:
once i have some sort of speed control, at the same time my led strip cylon mode need to sync its speed with the speed of the motor as it speeds up. Once it reaches a desired speed of 200, the lcd will say “fire!” you then click the fireButton2 and a burst of light flashes and the heatVents open and close rapidly. A temperature sensor on the back of the stepper is monitored and gives it a scale of safe and dangerous temperatures; if it gets too hot the stepper stops, the heatVents open and wait to cool down before returning to the standby phase. That’s what i have left to code and could use some help please!
#include <Servo.h>
#include <LiquidCrystal.h>
#include “FastLED.h”
#define PIN 9
#define STEPS 200
#define NUM_LEDS_PER_STRIP 35
CRGB redLeds[NUM_LEDS_PER_STRIP];
CRGB tealLeds[NUM_LEDS_PER_STRIP];
/*
JM-92 Pulse Cannon Mk I
by Jordan
2015
The brains and operations of the arm cannon
*/
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
const int analogTemp = A1; // Motor temperature
int triggerButton1 = 28; // Button that starts the cannon charging and barrel rotation
int fireButton2 = 30; // Button that fires a shot
const int elwireRelay = 24; // Electroluminesent Wire
const float baselineTemp = 20.0; // Ambient temp
int speedVal; // how fast the stepper should accelerate
int switchState = 1;
int pos = 0; // variable to store the servo position
Servo heatVent; // Allows heat to escape, Changed to pin 7 from pin 4
Stepper stepper(STEPS, 9, 8, 7, 6);
LiquidCrystal lcd(2, 3, 4, 5, 11, 12);
void setup() {
// put your setup code here, to run once:
// tell FastLED there’s 60 NEOPIXEL leds on pin 10
FastLED.addLeds<NEOPIXEL, 22>(redLeds, NUM_LEDS_PER_STRIP);
// tell FastLED there’s 60 NEOPIXEL leds on pin 11
FastLED.addLeds<NEOPIXEL, 26>(tealLeds, NUM_LEDS_PER_STRIP);
heatVent.attach(32);
pinMode(analogTemp, OUTPUT);
pinMode(elwireRelay, OUTPUT);
pinMode(triggerButton1, INPUT);
pinMode(fireButton2, INPUT);
//Declare which pins are what^
//Start up of Pulse Cannon
delay(1000);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(“Pulse Cannon MKI”);
lcd.setCursor(0, 1);
lcd.print(“Online”);
delay(5000);
lcd.clear();
lcd.print(“Running”);
lcd.setCursor(0, 1);
lcd.print(“Diagnostics”);
delay(2000);
lcd.clear();
lcd.print(“Please Stand By”);
// Start of component run through/Check.
digitalWrite(elwireRelay, HIGH);
delay(2000);
digitalWrite(elwireRelay, LOW);
delay(2000);
// Servo Initiate: Need to install flaps to calibrate
for (pos = 0; pos <= 180; pos += 10) // goes from 0 degrees to 180 degrees
// in steps of 1 degree
heatVent.write(pos); // tell servo to go to position in variable ‘pos’
delay(2000); // waits 15ms for the servo to reach the position
for (pos = 180; pos >= 0; pos -= 10) // goes from 180 degrees to 0 degrees
heatVent.write(pos); // tell servo to go to position in variable ‘pos’
delay(2000);
// set the speed of the motor to 30 RPMs
stepper.setSpeed(100);
stepper.step(STEPS);
delay(2000);
stepper.step(-STEPS);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.println(“Diagnostics”);
lcd.setCursor(0, 2);
lcd.println(“Complete!”);
delay(3000);
lcd.clear();
}
void loop() {
// Standby LED animation
for (int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
// set our current dot to red, green, and blue
redLeds = CRGB::Teal;
_ tealLeds = CRGB::Teal;_
* FastLED.show();*
* // clear our current dot before we move on*
_ redLeds = CRGB::Black;
tealLeds = CRGB::Black;
* delay(100);
//Showing how the cannon gets its energy somehow.
digitalWrite(elwireRelay, HIGH); //Showing how the cannon gets its energy somehow.
// This is the standby block: LED circles around the cannon and up and down, Temperature will be taken all the time*
* // We now wait for the user to click the charge button.
int sensorVal = analogRead(analogTemp); //Main standby mode when the user isnt doing anything.
lcd.setCursor(0, 0);
lcd.print(“Ready!”);
lcd.setCursor(0, 1);
lcd.print(“Core Temp is:”);
lcd.print(sensorVal);*
float voltage = (sensorVal / 1024.0) * 5.0;
float temperature = (voltage - .5) * 100;_
* if (digitalRead(triggerButton1) == HIGH) {*
* stepper.setSpeed(0);*
* stepper.step(STEPS);*
* long speedVal = stepper.setSpeed();*
* {*
* }*
* }*
* }*