几天以来,我一直在努力学习arduino脚本,经过无数次的试验和错误,我已经设法将其归结为一些错误,但我不能为我的生活弄明白而且我是确定它会变得非常简单。
我尽可能多地搜索网络,但我仍然找不到问题所在。 我看到这个网站的好人是多么美妙,所以我请求你的帮助。
任何帮助都会很棒
这是完整的代码......
#include <Stepper.h>
void setup() {
const int stepsPerRevolution = 400; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper beamsplitter(stepsPerRevolution, 8, 9, 10, 11);
int LaserState = LOW; // The variable that stores the state of the laser beam.
int sensor = 8 ; // Change this value to calibrate your harp's sensor
int delaylaser = 2000; // If you increase this, the laser will be brighter, but the harp will be less fluid
int motorspeed = 100; // This variable affects the speed, and fluidity of the harp.
int stepsize = 2; //size between beams
int LaserPin = 7; // Tell the arduino that the laser is on pin 7
int startupspeed = 3;
int pos = 0; // position of the laser
int beams = 12; // number of beams
int pitch;
void setup() {
pinMode(LaserPin, OUTPUT); // Setup for laser.
pinMode(6, OUTPUT); // Setup for status led.
digitalWrite(LaserPin, HIGH);
delay(1500);
//start sequence
beamsplitter.setSpeed(startupspeed);
beamsplitter.step((-beams * stepsize / 2)-1);
for (int x = 1; x < 60; x++) {
if (x<30) {
startupspeed = 103 - (100/pow(x, 1.0/4.5));
}
if (x>=30) {
startupspeed = 103 - (100/pow(x, 1.0/1.0));
}
beamsplitter.setSpeed(startupspeed);
for (int pos = beams; pos > 0; pos--) { // turn in other direction
beamsplitter.step(stepsize); // direction
}
for (int pos = 0; pos < beams; pos++) { // turn in other direction
beamsplitter.step(-stepsize); // direction
}
beamsplitter.setSpeed(motorspeed);
Serial.begin(31250);
}
}
void loop() {
for (pos = 1; pos < beams; pos++) { // turn in first direction
beamsplitter.step(stepsize); // switch position
//delayMicroseconds(delaymotor);
digitalWrite(LaserPin, HIGH); // turn on laser
delayMicroseconds(delaylaser / 2);
if ( (analogRead(0) > sensor ))\ // If the sensor gets a signalx
{
digitalWrite(6, HIGH); // Switch on status led.
noteOn(); // Play note 3
}
else if (analogRead(0) < sensor ) // If the sensor does not get a signal:
{
digitalWrite(6, LOW); // Switch off the status led.
noteOff(); // Stop playing note 2.
}
delayMicroseconds(delaylaser / 2);
digitalWrite(LaserPin, LOW); // Turn off the Laser.
}
beamsplitter.step(beams*stepsize);
}
它给了我这些错误......
sketch_oct07k.ino: In function 'void setup()':
sketch_oct07k.ino:33:14: error: a function-definition is not allowed here before '{' token
sketch_oct07k.ino:129:1: error: expected '}' at end of input
任何人都能帮助一个可怜的灵魂?
答案 0 :(得分:0)
您复制了一些代码。
在第3行和第33行有一个void setup(){
。我假设它是你需要的第33行的第二个,否则所有变量都是本地设置。