servos aansturen met graupner zender

algemene C code
Berichten: 14
Geregistreerd: 25 Nov 2015, 13:31

servos aansturen met graupner zender

Berichtdoor swift » 18 Okt 2016, 15:05

made cpp code
/*
State change detection (edge detection)


This is based on example code is in the public domain.

http://arduino.cc/en/Tutorial/ButtonStateChange

Servo

https://www.arduino.cc/en/Reference/Servo


*/
#include <Servo.h>


// this constant won't change:
const int buttonPin = A0; // the pin that 1st the digital pushbutton is attached to
const int buttonPin1 = A1; // the pin that 2nd the digital pushbutton is attached to
const int buttonPin2 = A2; // the pin that 3th the servo pushbutton is attached to
const int buttonPin3 = A3; // the pin that 5th the servo pushbutton is attached to
const int buttonPin4 = A4; // the pin that 6th the servo pushbutton is attached to
const int buttonPin5 = A5; // the pin that 9th the servo pushbutton is attached to
const int buttonPin6 = 2; // the pin that 10th the servo pushbutton is attached to
const int buttonPin7 = 4; // the pin that 11th the servo pushbutton is attached to

Servo myservo3;
Servo myservo5;
Servo myservo6;
Servo myservo9;
Servo myservo10;
Servo myservo11;

const int ledPin1 = 12; // the pin that the LED is attached to
const int ledPin2 = 13; // the pin that the LED is attached to

// Variables will change:

// 1st input/output
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button

// 2nd input/output
int buttonPushCounter1 = 0; // counter for the number of button presses
int buttonState1 = 0; // current state of the button
int lastButtonState1 = 0; // previous state of the button

// 3th input/output
int buttonPushCounter2 = 0; // counter for the number of button presses
int buttonState2 = 0; // current state of the button
int lastButtonState2 = 0; // previous state of the button

// 4th input/output
int buttonPushCounter3 = 0; // counter for the number of button presses
int buttonState3 = 0; // current state of the button
int lastButtonState3 = 0; // previous state of the button

// 5th input/output
int buttonPushCounter4 = 0; // counter for the number of button presses
int buttonState4 = 0; // current state of the button
int lastButtonState4 = 0; // previous state of the button

// 6th input/output
int buttonPushCounter5 = 0; // counter for the number of button presses
int buttonState5 = 0; // current state of the button
int lastButtonState5 = 0; // previous state of the button

// 7th input/output
int buttonPushCounter6 = 0; // counter for the number of button presses
int buttonState6 = 0; // current state of the button
int lastButtonState6 = 0; // previous state of the button

// 8th input/output
int buttonPushCounter7 = 0; // counter for the number of button presses
int buttonState7 = 0; // current state of the button
int lastButtonState7 = 0; // previous state of the button




void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
pinMode(buttonPin6, INPUT);
pinMode(buttonPin7, INPUT);


// initialize the LED as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);

// initelize the and attach the servos
myservo3.attach(3);
myservo5.attach(5);
myservo6.attach(6);
myservo9.attach(9);
myservo10.attach(10);
myservo11.attach(11);

// initialize serial communication:
Serial.begin(9600);
}


void loop() {


//-------------------------------------------------

// read the pushbutton input pin1 1st servo (myservo3) :
buttonState2 = digitalRead(buttonPin2);

// compare the buttonState to its previous state
if (buttonState2 != lastButtonState2) {
// if the state has changed, increment the counter
if (buttonState2 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter2++;
Serial.println("high servo 3");
Serial.print("number of button2 pushes: ");
Serial.println(buttonPushCounter2);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("low servo 3");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState2 = buttonState2;


// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter2 % 2 == 0) {
myservo3.write (50);
} else {
myservo3.write (150);
}

//-------------------------------------------------


// read the pushbutton input pin 2nd servo (myservo5) :
buttonState3 = digitalRead(buttonPin3);

// compare the buttonState to its previous state
if (buttonState3 != lastButtonState3) {
// if the state has changed, increment the counter
if (buttonState3 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter3++;
Serial.println("servo 5 high");
Serial.print("number of button3 pushes: ");
Serial.println(buttonPushCounter3);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("servo 5 low");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState3 = buttonState3;


// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter3 % 2 == 0) {
myservo5.write (50);
} else {
myservo5.write (150);
}

//-------------------------------------------------


// read the pushbutton input pin 3th servo (myservo6) :
buttonState4 = digitalRead(buttonPin4);

// compare the buttonState to its previous state
if (buttonState4 != lastButtonState4) {
// if the state has changed, increment the counter
if (buttonState4 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter4++;
Serial.println("servo 4 high");
Serial.print("number of button4 pushes: ");
Serial.println(buttonPushCounter4);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("servo 6 low");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState4 = buttonState4;


// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter4 % 2 == 0) {
myservo6.write (50);
} else {
myservo6.write (150);
}


//-------------------------------------------------


// read the pushbutton input pin 4th servo (myservo9) :
buttonState5 = digitalRead(buttonPin5);

// compare the buttonState to its previous state
if (buttonState5 != lastButtonState5) {
// if the state has changed, increment the counter
if (buttonState5 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter5++;
Serial.println("servo 9 high");
Serial.print("number of button5 pushes: ");
Serial.println(buttonPushCounter5);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("servo 9 low");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState5 = buttonState5;


// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter5 % 2 == 0) {
myservo9.write (50);
} else {
myservo9.write (150);
}


//-------------------------------------------------


// read the pushbutton input pin 5th servo (myservo10) :
buttonState6 = digitalRead(buttonPin6);

// compare the buttonState to its previous state
if (buttonState6 != lastButtonState6) {
// if the state has changed, increment the counter
if (buttonState6 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter6++;
Serial.println("servo 10 high");
Serial.print("number of button6 pushes: ");
Serial.println(buttonPushCounter6);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("servo 10 low");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState6 = buttonState6;


// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter6 % 2 == 0) {
myservo10.write (50);
} else {
myservo10.write (150);
}


//-------------------------------------------------


// read the pushbutton input pin 6th servo (myservo11) :
buttonState7 = digitalRead(buttonPin7);

// compare the buttonState to its previous state
if (buttonState7 != lastButtonState7) {
// if the state has changed, increment the counter
if (buttonState7 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter7++;
Serial.println("servo 11 high");
Serial.print("number of button7 pushes: ");
Serial.println(buttonPushCounter7);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("servo 11 low");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState7 = buttonState7;


// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter7 % 2 == 0) {
myservo11.write (50);
} else {
myservo11.write (150);
}
delay (200);
}

we krijgen een fout code ??? hulp gevraagd

Advertisement

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: servos aansturen met graupner zender

Berichtdoor nicoverduin » 18 Okt 2016, 17:08

Da's heel mooi.... Maar eh... welke?
Maw. Zet de tekst van de fout even hier neer.

[moderator pet op]Is dit een Raspberry probleem of een Arduino probleem[/moderator pet op]
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 14
Geregistreerd: 25 Nov 2015, 13:31

Re: servos aansturen met graupner zender

Berichtdoor swift » 18 Okt 2016, 19:36

hieronder de fout code die we kregen




Arduino: 1.6.9 (Windows XP), Board:"Arduino Nano, ATmega328"

C:\Documents and Settings\Ria van Loock\Mijn documenten\Arduino\sketch_oct17a\sketch_oct17a.ino: In function 'void setup()':

sketch_oct17a:355: error: redefinition of 'void setup()'

void setup() {

^

sketch_oct17a:83: error: 'void setup()' previously defined here

void setup() {

^

C:\Documents and Settings\Ria van Loock\Mijn documenten\Arduino\sketch_oct17a\sketch_oct17a.ino: In function 'void loop()':

sketch_oct17a:360: error: redefinition of 'void loop()'

void loop() {

^

sketch_oct17a:112: error: 'void loop()' previously defined here

void loop() {

^

exit status 1
redefinition of 'void setup()'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: servos aansturen met graupner zender

Berichtdoor nicoverduin » 18 Okt 2016, 20:02

De sketch is prima. Wat wel het geval kan zijn is dat je installatie van de IDE vernaggelt is of dat je meerdere tabbladen open hebt staan in de IDE waardoor je dus meerdere programma's met setup open hebt staan. Als je uitsluitend deze sketch hebt open staan dan is de installatie van de IDE niet 100%. Met welke versie draai je?
Of heb je aan het eind van die sketch ook nog eens de oorspronkelijke setup en loop staan ?
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 14
Geregistreerd: 25 Nov 2015, 13:31

Re: servos aansturen met graupner zender

Berichtdoor swift » 19 Okt 2016, 11:48

arduino1.6.9

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: servos aansturen met graupner zender

Berichtdoor nicoverduin » 19 Okt 2016, 13:00

Dan lijkt het erop dat je aan het einde van die sketch nog eea hebt staan. Anders gewoon een nieuwe sketch maken en de code van hierboven ff kopieren. Wel bij een nieuwe sketch de oude setup() en loop9) functies verwijderen. Anders ben je net zover als nu.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 14
Geregistreerd: 25 Nov 2015, 13:31

Re: servos aansturen met graupner zender

Berichtdoor swift » 21 Okt 2016, 16:48

Heb met een nieuwe Arduino Nano geprobeerd en nu word de sketch zondermeer ingeladen

Bedankt voor de hulp

mvg

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: servos aansturen met graupner zender

Berichtdoor nicoverduin » 21 Okt 2016, 20:25

ff voor de duidelijkheid. Dit heeft niets met de hardware te maken. Zover kom je niet eens omdat de compilatie al stuk liep. Dit is puur een software probleem. Dus met het andere bordje was het net zo goed gegaan,
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Terug naar C code

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 12 gasten