» »

Pomoč C++

Pomoč C++

samo111 ::

Pozdravljeni,

Rabil bi pomoč pri naslednjem programu, saj mi javlja napako, Se vam zahvaljujem že vnaprej :



Servo servo_Vertical; // create servo object to control a servo (Vertical)
Servo servo_Horizonal; // create servo object to control a servo (Horizontal)
int val_Vertical=90; // variable to read the value from the analog pin
int val_Horizonal=90; // variable to read the value from the analog pin

//===============================================================================
const int referenceVolts = 5;
const float R1 = 51000.0; //Resistor #1 (51K)
const float R2 = 100000.0; //Resistor #2 (100K)
const float Ratio = (R1/R2);
const float resistorFactor = ((referenceVolts/Ratio)/1023.0); // eq 0.014471088

const int TolarencePin = A4; // Use Potentiometer for Tolarence Settings
const int solarPin = A5; // +V from Solar Panel connected to analog pin
float v = 0;
//
const int LDR_1_Left = A0; // LDR connected to Analog Pin 0 Left
const int LDR_2_Right = A1; // LDR connected to Analog Pin 1 Right
const int LDR_3_Down = A2; // LDR connected to Analog Pin 2 Down
const int LDR_4_Up = A3; // LDR connected to Analog Pin 3 Up
//
int LDR_1_Left_val = 0;
int LDR_2_Right_val = 0;
int LDR_4_Up_val = 0;
int LDR_3_Down_val = 0;
//
//LEDs 10=UP; 11=Right; 12=Left; 13=Down
int ledPins[] = {10,11,12,13};
//
int dtime = 25;
int Tolarence = 0;

void setup()
{
servo_Vertical.attach(5); // attaches the servo on pin 5 (Elevation) to the servo object
servo_Horizonal.attach(6); // attaches the servo on pin 6 (Horizontal) to the servo object

//Setup LED Pins as OUTPUT
for (int x = 0; x < 4; x++){
pinMode(ledPins[x], OUTPUT);
}
Serial.begin(9600);
}

void loop()
{
reset_leds();
read_potentiometer();
read_voltage();
read_LDRs();
adjust_Servos();

display_status();
delay(dtime); // waits for the servo to move
}

//=========================================================================

// Subs....


//=========================================================================
void reset_leds(){
for (int x = 0; x < 4; x++){
digitalWrite(ledPins[x], LOW);
}
}
//=========================================================================
void read_potentiometer(){
// Use Potentiometer for Tolarence Settings
Tolarence = analogRead(TolarencePin)/4;
}

//=========================================================================
void read_voltage(){
v = analogRead(solarPin);
v *= resistorFactor;
} // end read_voltage

//=========================================================================
void read_LDRs(){
// Set the LDRs in an x config and label the LDRs from 1-4
// \ 4 /
// 1 X 2
// / 3 \
///arduino LDR Pins 10=UP; 11=Right; 12=Left; 13=Down
LDR_1_Left_val = analogRead(LDR_1_Left);
LDR_2_Right_val = analogRead(LDR_2_Right);
LDR_3_Down_val = analogRead(LDR_3_Down);
LDR_4_Up_val = analogRead(LDR_4_Up);
} //end read_LDRs

//=========================================================================
void adjust_Servos(){

int avg_Left_Top = (LDR_1_Left_val + LDR_4_Up_val) / 2; // average value Left_Top
int avg_Left_Botton = (LDR_1_Left_val + LDR_3_Down_val) / 2; // average value Left_Botton
int avg_Right_Top = (LDR_2_Right_val + LDR_4_Up_val) / 2; // average value Right_Top
int avg_Right_Botton = (LDR_2_Right_val + LDR_3_Down_val) / 2; // average value Right_Botton

int dvert = (avg_Left_Top + avg_Right_Top) - (avg_Left_Botton + avg_Right_Botton); // check the diffirence of up and down
int dhoriz = (avg_Left_Top + avg_Left_Botton) - (avg_Right_Top + avg_Right_Botton);// check the diffirence og left and rigt

// Using the tolarence value stop servo seeking
// Check Vertical
if (-1*Tolarence > dvert || dvert > Tolarence){ // check if the diffirence is in the tolerance else change vertical angle
if ((avg_Left_Top + avg_Right_Top) > (avg_Left_Botton + avg_Right_Botton)){
//adjust Vertical Servo Down
digitalWrite(ledPins[3], HIGH); //Blink the Bottom LED
val_Vertical = ++val_Vertical;
if (val_Vertical > 179){
val_Vertical = 179;
}
}
else if ((avg_Left_Top + avg_Right_Top) < (avg_Left_Botton + avg_Right_Botton)){
//adjust Vertical Servo Up
val_Vertical= --val_Vertical;
digitalWrite(ledPins[0], HIGH); //Blink the Top LED
if (val_Vertical < 1){
val_Vertical = 1;
}
}
servo_Vertical.write(val_Vertical);
}
//Check Horizonal
if (-1*Tolarence > dhoriz || dhoriz > Tolarence){ // check if the diffirence is in the tolerance else change horizontal angle
if ((avg_Left_Top + avg_Left_Botton) > (avg_Right_Top + avg_Right_Botton)){
//adjust Horizonal Servo Left
val_Horizonal = --val_Horizonal;
digitalWrite(ledPins[1], HIGH); //Blink the Left LED
if (val_Horizonal < 1){
val_Horizonal = 1;
}
}
else if ((avg_Left_Top + avg_Left_Botton) < (avg_Right_Top + avg_Right_Botton)){
//adjust Horizonal Servo Right
val_Horizonal = ++val_Horizonal;
digitalWrite(ledPins[2], HIGH); //Blink the Right LED
if (val_Horizonal > 179){
val_Horizonal = 179;
}
}
else if ((avg_Left_Top + avg_Left_Botton) == (avg_Right_Top + avg_Right_Botton)){
// nothing
}
servo_Horizonal.write(val_Horizonal);
}
} // end adjust servos

//========================================================================
void display_status(){
Serial.print("Solar Panel Volts: ");
Serial.print(v);

Serial.print(" Servo Horizontal: ");
Serial.print(val_Horizonal);
Serial.print(" Servo Vertical: ");
Serial.print(val_Vertical);

Serial.print(" LDR_1_L: ");
Serial.print(LDR_1_Left_val);
Serial.print(" LDR_2_R: ");
Serial.print(LDR_2_Right_val);
Serial.print(" LDR_3_D: ");
Serial.print(LDR_3_Down_val);
Serial.print(" LDR_4_U: ");
Serial.print(LDR_4_Up_val);

Serial.print(" Tolarence: ");
Serial.println(Tolarence);
} //end display status

kow ::

In napaka se glasi?

          ::

Sketch -> Include Library -> Servo

samo111 ::

na začetku : Sketch -> Include Library -> Servo sem pozabil pripisat ko sem dodajal program sem na forum.

Javlja mi napako pri : float v=0 ; in sicer: expected unqalifield_id befor "float"

videc ::

Tule je težava:
const int TolarencePin = A4; // Use Potentiometer for Tolarence Settings
const int solarPin = A5; // +V from Solar Panel connected to analog pin
float v = 0;
//
const int LDR_1_Left = A0; // LDR connected to Analog Pin 0 Left
const int LDR_2_Right = A1; // LDR connected to Analog Pin 1 Right
const int LDR_3_Down = A2; // LDR connected to Analog Pin 2 Down
const int LDR_4_Up = A3; // LDR connected to Analog Pin 3 Up

Će pogledaš primer na tej strani, vidiš, da bere iz pina 2, na način:
https://www.arduino.cc/en/Tutorial/Digi...
The first thing you need to do in the main loop of your program is to establish a variable to hold the information coming in from your switch. Since the information coming in from the switch will be either a "1" or a "0", you can use an int datatype. Call this variable sensorValue, and set it to equal whatever is being read on digital pin 2. You can accomplish all this with just one line of code:

int sensorValue = digitalRead(2); 

Pa še pinout:

A1-A5 so res naslovi, naslavljaš jih pa z indeksom, torej A0 je 0, A1 je 1, ...
Še pinout:

Še en primer:
https://www.arduino.cc/en/Reference/Dig...
int ledPin = 13; // LED connected to digital pin 13
int inPin = 7;   // pushbutton connected to digital pin 7
int val = 0;     // variable to store the read value

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
  pinMode(inPin, INPUT);      // sets the digital pin 7 as input
}

void loop()
{
  val = digitalRead(inPin);   // read the input pin
  digitalWrite(ledPin, val);    // sets the LED to the button's value
}


Pa daj zamikaj kodo, da bo bolj berljiva.

Eh, sem povsem narobe napisal... My bad.

Ignoriraj vse, kar sem napisal.

Zgodovina sprememb…

  • spremenilo: videc ()

samo111 ::

v bistvo mi še vedno javlja napako ne glede da sem upošteval tvoj nasvet in to prav pri vseh vrsticah enako nakao " expected unqalifield_id befor ( float ,int,.. )"

kow ::

Daj ti raje copy pasteaj kaj ti vrne compiler. Da vidimo tocen output, ker ocitno se ne prepisati ne zmores brez napak.

samo111 ::

sketch_solarni_sledilnik.ino: In function 'void setup()':

sketch_solarni_sledilnik.ino:58:13: error: 'ledPins' was not declared in this scope

sketch_solarni_sledilnik.ino:60:5: error: 'serial' was not declared in this scope

sketch_solarni_sledilnik.ino: In function 'void loop()':

sketch_solarni_sledilnik.ino:67:16: error: 'read_LDR' was not declared in this scope

sketch_solarni_sledilnik.ino: In function 'void reset_leds()':

sketch_solarni_sledilnik.ino:81:24: error: 'ledPins' was not declared in this scope

sketch_solarni_sledilnik.ino: In function 'void read_potentiometer()':

sketch_solarni_sledilnik.ino:97:23: error: expected ';' before numeric constant

sketch_solarni_sledilnik.ino: In function 'void read_LDRs()':

sketch_solarni_sledilnik.ino:118:17: error: expected ';' before 'LDR_2_Right_val'

sketch_solarni_sledilnik.ino:119:17: error: 'LDR_3_Down_val' was not declared in this scope

sketch_solarni_sledilnik.ino:119:45: error: 'LDR_3_Down' was not declared in this scope

sketch_solarni_sledilnik.ino:120:17: error: 'LDR_4_Up_val' was not declared in this scope

sketch_solarni_sledilnik.ino:120:43: error: 'LDR_4_Up' was not declared in this scope

sketch_solarni_sledilnik.ino: In function 'void adjust_Servos()':

sketch_solarni_sledilnik.ino:127:55: error: 'LDR_4_Up_val' was not declared in this scope

sketch_solarni_sledilnik.ino:132:102: error: 'kontrola' was not declared in this scope

sketch_solarni_sledilnik.ino:132:111: error: expected ';' before 'razlike'

sketch_solarni_sledilnik.ino:134:112: error: expected ';' before 'razlike'

sketch_solarni_sledilnik.ino:199:29: error: expected '}' at end of input

'ledPins' was not declared in this scope


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

GPS modul NEO-6M GPS in Arduino Nano

Oddelek: Elektrotehnika in elektronika
7674 (617) llc
»

Kdo se spozna na ESP8266 in Arduino?

Oddelek: Pomoč in nasveti
182066 (1644) chiiiii
»

Arduino in luči (strani: 1 2 )

Oddelek: Elektrotehnika in elektronika
9811252 (8878) FX6300B
»

Zelo pocasno utripanje LED diode (strani: 1 2 )

Oddelek: Elektrotehnika in elektronika
508253 (7458) a13misko
»

[C] MySQL

Oddelek: Programiranje
292681 (1703) Tutankhamun

Več podobnih tem