Both sketches work fine by themselves.
I get that the setup and void and sections are independent (so to speak)
I’ve moved those portions into the correct areas.
I must be doing something wrong. I just don’t understand enough of C++ (or any coding for that matter) to really even be here. But I am trying.
So maybe someone can help me and fix this?
here’s the idea
I have 3 sets of LED’s to be powered eventually, all with the same LED code. I’m currently only using one to get both portions of my project to work properly together before I start adding more LED’s.
Each set of LEDs have 4 bulbs. I am also attempting to run a Stepper motor to lower and raise an (Unidentified Flying) Object (which will have the lights inside it).
I can follow the pin coding pretty well, and understand the change of values, but it’s the syntax errors that keep getting me. Especially the missing { when they are there.
But I have other errors as well. Maybe someone could fix it, and tell me what they did, why, and how to avoid these mistakes again?
I appreciate any help, and please take it easy on me. I’ve only had this UNO for about 3 weeks. I’ve copied files from online which have made each part of the project work (don’t remember where I got em though), and am just having issues merging them. You tube hasn’t been much help, and it’s late, and I don’t have time to keep messing with it tonight. I’d really like to get to the point where all this works and I can start soldering it together so that I can clean up my kitchen table before my wife stabs me with a spoon.
/*
* MotorKnob
*
* A stepper motor follows the turns of a potentiometer
* (or other sensor) on analog input 0.
*
* http://www.arduino.cc/en/Reference/Stepper
* This example code is in the public domain.
*/
// Pin 2 IN 1
// Pin 3 IN 2
// Pin 4 IN 3
// Pin 5 IN 4
// 5V to battery, ground to Gnd on Arduino
#include "Stepper.h";
// change this to the number of steps on your motor
#define STEPS 48
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
// Define Constants
// Steps per Rev
const float STEPS_PER_REV = 32;
const float GEAR_RED = 64;
const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED;
//Number of steps per geared rotation
// the previous reading from the analog input
int previous = 0;
int StepsRequired;
Stepper stepper(STEPS, 2, 4, 3, 5);
/* Lights Portion for Green LED
*
*/
byte ledPin[] = {9, 8, 7, 6, 7, 8, 9}; // Create array for LED pins
int ledDelay = 10; // delay between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
void setup() [
// set the speed of the motor to 30 RPMs
stepper.setSpeed(700);
}
{for (int x=0; x<10; x++)
{
// set all pins to output
pinMode(ledPin[6, 7, 8, 9], OUTPUT);
}
changeTime = millis();
]
void loop() {
// get the sensor value
int val = analogRead(0);
// move a number of steps equal to the change in the
// sensor reading
stepper.step(10250);
delay(2000);
stepper.step(-10250);
delay(10000);
// remember the previous value of the sensor
previous = val;
}
if ((millis() - changeTime) > ledDelay)
{
// if it has been ledDelay ms since last change
changeLED();
changeTime = millis();
}
}
void changeLED()
{
for (int x=0; x<10; x++)
{
// turn off all LED's
digitalWrite(ledPin[x], LOW);
}
digitalWrite(ledPin[currentLED], HIGH); // turn on the current LED
currentLED += direction; // increment by the direction value
// change direction if we reach the end
if (currentLED == 9) {direction = -1;}
if (currentLED == 0) {direction = 1;}
}