Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion erfordert derzeit den Zugriff auf die Seite über den integrierten Safari-Browser.
Moin Patrick,
Jepp, habe ich.
Es gibt eine blockierende Variante per pulseIn() Funktion oder nicht blockierend per Interrupt.
Erzähl doch mal was du machen möchtest.
#include <debug.h>
#include <makros.h>
#include <RCReceive.h>
/*
RC_Template.ino - Template for RC Receiver enabled programs - Version 0.2
Copyright (c) 2012 Wilfried Klaas. All right reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
const byte PIN_RC = 2;
// Der Empfänger
RCReceive rcReceiver;
void setup() {
rcReceiver.attach(PIN_RC);
// put your setup code here, to run once:
}
void loop() {
// Aktuellen RC-Wert lesen
rcReceiver.poll();
// Nullpunktsbestimmung ?
if (rcReceiver.hasNP() && !rcReceiver.hasError()) {
doWork();
} else if (rcReceiver.hasError()) {
// Fehlerbehandlung failsafe oder sowas...
}
}
void doWork() {
byte value = rcReceiver.getValue();
// put your main code here, to run repeatedly:
}
#include <debug.h>
#include <makros.h>
#include <RCReceive.h>
/*
RC_Template.ino - Template for RC Receiver enabled programs - Version 0.2
Copyright (c) 2012 Wilfried Klaas. All right reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
const byte PIN_RC = 24;
// Der Empfänger
RCReceive rcReceiver;
void setup()
{
Serial.begin(9600);
rcReceiver.attach(PIN_RC);
// put your setup code here, to run once:
}
void loop() {
// Aktuellen RC-Wert lesen
rcReceiver.poll();
// Nullpunktsbestimmung ?
if (rcReceiver.hasNP() && !rcReceiver.hasError()) {
doWork();
} else if (rcReceiver.hasError()) {
// Fehlerbehandlung failsafe oder sowas...
}
}
void doWork() {
byte value = rcReceiver.getValue();
// put your main code here, to run repeatedly:
Serial.println(value);
}
#include <debug.h>
#include <makros.h>
#include <RCReceive.h>
/*
RC_Template.ino - Template for RC Receiver enabled programs - Version 0.2
Copyright (c) 2012 Wilfried Klaas. All right reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
const byte PIN_RC = 24; //Signalanschluss
const int Motor1 = 2; //PWM-Motoranschluss
const int Rel1 = 25; //Relais 1 zum Umschalten zwischen Drehrichtungen
int Mot1 = 0;
// Der Empfänger
RCReceive rcReceiver;
void setup()
{
pinMode(Rel1,OUTPUT);
Serial.begin(9600);
rcReceiver.attach(PIN_RC);
// put your setup code here, to run once:
}
void loop()
{
// Aktuellen RC-Wert lesen
rcReceiver.poll();
// Nullpunktsbestimmung ?
if (rcReceiver.hasNP() && !rcReceiver.hasError()) {
doWork();
} else if (rcReceiver.hasError()) {
// Fehlerbehandlung failsafe oder sowas...
}
}
void doWork()
{
byte value = rcReceiver.getValue();
// put your main code here, to run repeatedly:
Serial.println(value);
if (value > 122)
{
Mot1 =map(value,122,243,0,255);
analogWrite(Motor1,Mot1);
}
if (value < 117)
{
Mot1 =map(value,117,0,0,255);
analogWrite(Motor1,Mot1);
digitalWrite(Rel1,HIGH);
}
else
{
digitalWrite(Rel1,LOW);
}
}
#include <Servo.h>
Servo SpeedServo;
volatile uint8_t LastInterruptState = PIND;
// Variablen fuer die Geschwindigkeit
volatile uint16_t ReceivedSpeedValues[4] = {1500, 1500, 1500, 1500};
volatile uint16_t ReceivedSpeedValuesSum = 6000;
volatile uint8_t ReceivedSpeedValuesIndex = 0;
volatile uint32_t LastSpeedChange = micros();
volatile uint16_t LastSpeedValue = 0;
#define PinSpeedServo 6 // Servo Ausgang fuer die Geschwindigkeit
void SpeedPositionInterrupt()
{
uint32_t nMicros = micros();
uint16_t nDifference = (uint16_t)(nMicros - LastSpeedChange);
if ( (nDifference > 900) && ( nDifference < 2100))
{
ReceivedSpeedValuesSum -= ReceivedSpeedValues[ReceivedSpeedValuesIndex];
ReceivedSpeedValues[ReceivedSpeedValuesIndex] = nDifference;
ReceivedSpeedValuesSum += nDifference;
ReceivedSpeedValuesIndex = ( ( ReceivedSpeedValuesIndex + 1 ) & 0x03 ); // Index erhoehen und ggf. von 4 auf 0 springen
nDifference = ( ReceivedSpeedValuesSum >> 2 ); // durch 4 teilen
LastSpeedValue = nDifference;
}
LastSpeedChange = nMicros;
}
ISR(PCINT2_vect)
{
uint8_t PinState = PIND;
uint8_t PinChanges = PinState ^ LastInterruptState;
if (PinChanges & (1<<PCINT18))
SpeedPositionInterrupt();
LastInterruptState = PinState;
}
void setup()
{
SpeedServo.attach( PinSpeedServo );
PCICR |= (1 << PCIE2);
PCMSK2 |= ( ( 1<<PCINT18) | (1<<PCINT19) | (1<<PCINT20) | (1<<PCINT21));
sei();
}
void loop()
{
uint16_t nServoValue = LastSpeedValue;
// do something with Servo value...
SpeedServo.writeMicroseconds(nServoValue);
delay (20);
}
Wir verwenden essentielle Cookies, damit diese Website funktioniert, und optionale Cookies, um den Komfort bei der Nutzung zu verbessern.
Siehe weitere Informationen und konfiguriere deine Einstellungen