Projekt:Tüftlerclub/Werkstatt
Erscheinungsbild
Bjarne
[Bearbeiten]- Omnibit mit Servo-Kanone
- Makecode
Kran
[Bearbeiten]- IR / Servo
#include <IRremote.h>
#include <Servo.h>
int IrWert = 0;
const int IrPin = 3;
int pins[] = {A0,A1,A2,A3,A4,A5,A6,A7};
void setup() {
IrReceiver.begin(IrPin);
for (int i = 0; i < 8 ; i++) {
pinMode(pins[i],OUTPUT);
}
for (int i = 0; i < 8 ; i++) {
digitalWrite(pins[i],LOW);
}
}
void loop() {
if (IrReceiver.decode()) {
IrReceiver.resume();
IrWert = IrReceiver.decodedIRData.command;
}
}
Lijo
[Bearbeiten]Funk
[Bearbeiten]Pneumatik: IR > 2 Ventile
[Bearbeiten]#include <IRremote.h>
#include <Servo.h>
// 1 = 69;
// 2 = 70;
// 3 = 71;
// 4 = 68;
// 5 = 64;
// 6 = 67;
// 7 = 7;
// 8 = 21;
// 9 = 9;
// 0 = 25;
// Asterisk = 22;
// Rhombus = 13;
// OK = 28;
// Up = 24;
// Down = 82;
// Left = 8;
// Right = 90;
const int IR_pin = 3;
int IrWert = 0;
const int Z1_pin = 9;
const int Z2_pin = 10;
Servo pneu_servoZ1;
Servo pneu_servoZ2;
void setup() {
IrReceiver.begin(IR_pin);
pneu_servoZ1.attach(Z1_pin);
pneu_servoZ1.write(40);
pneu_servoZ2.attach(Z2_pin);
pneu_servoZ2.write(40);
Serial.begin(9600);
Serial.println("verbunden");
}
void loop() {
if (IrReceiver.decode()) {
IrReceiver.resume();
IrWert = IrReceiver.decodedIRData.command;
if (IrWert == 24) {
pneu_servoZ1.write(55);
delay(500);
Serial.println("Z1 aus");
}
if (IrWert == 22) {
pneu_servoZ1.write(40);
delay(500);
Serial.println("Z1 gesperrt");
}
if (IrWert == 82) {
pneu_servoZ1.write(25);
delay(500);
Serial.println("Z1 ein");
}
if (IrWert == 8) {
pneu_servoZ2.write(55);
delay(500);
Serial.println("Z2 aus");
}
if (IrWert == 13) {
pneu_servoZ2.write(40);
delay(500);
Serial.println("Z2 gesperrt");
}
if (IrWert == 90) {
pneu_servoZ2.write(25);
delay(500);
Serial.println("Z2 ein");
}
}
}
Cord & Jan-Helge
[Bearbeiten]- MakeCode
- MakeCode - alle Motoren
- MakeCode
- YouTube: Kettenfahrzeug mit Servolenkung
- YouTube: Spielzeugkamera ausprobiert
Fernsteuerung
[Bearbeiten]- https://funduino.de/nr-24-joystick-modul-v1-a
- https://wolles-elektronikkiste.de/nrf24l01-2-4-ghz-funkmodule
Joystick
[Bearbeiten]void setup() {
pinMode(2,OUTPUT); // M1
pinMode(3,OUTPUT); // (PWM)
pinMode(4,OUTPUT); // M2
pinMode(5,OUTPUT); // (PWM)
pinMode(6,OUTPUT); // PWM
pinMode(9,OUTPUT); // PWM
pinMode(10,OUTPUT); // PWM
pinMode(18,OUTPUT); // M3
pinMode(19,OUTPUT);
pinMode(20,OUTPUT); // M4
pinMode(21,OUTPUT);
}
void loop() {
if (analogRead(A0)<100){
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
analogWrite();
}
if (analogRead(A0)>700){
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
analogWrite();
}
if (analogRead(A1)<100){
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
analogWrite();
}
if (analogRead(A1)>700){
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
analogWrite();
}
if (analogRead(A2)<100){
digitalWrite(18,LOW);
digitalWrite(19,HIGH);
analogWrite();
}
if (analogRead(A2)>700){
digitalWrite(18,HIGH);
digitalWrite(19,LOW);
analogWrite();
}
if (analogRead(A3)<100){
digitalWrite(20,HIGH);
digitalWrite(21,LOW);
analogWrite();
}
if (analogRead(A3)>700){
digitalWrite(20,HIGH);
digitalWrite(21,LOW);
analogWrite();
}
delay(100);
}
Greifarm
[Bearbeiten]void setup() {
pinMode(2, OUTPUT); // M1
pinMode(3, OUTPUT); // (PWM)
pinMode(4, OUTPUT); // M2
pinMode(5, OUTPUT); // (PWM)
pinMode(6, OUTPUT); // PWM
pinMode(9, OUTPUT); // PWM
pinMode(10, OUTPUT); // PWM
pinMode(11, OUTPUT); // PWM
pinMode(18, OUTPUT); // M3
pinMode(19, OUTPUT);
pinMode(20, OUTPUT); // M4
pinMode(21, OUTPUT);
}
int pwm(int x) {
int out;
if (x < 512) { //Check if joystick is above, below, or at the middle and calculate the unmapped output
x = 512 - x;
}
if (x > 512) {
x = x - 512;
}
if (x == 512) {
x = 0;
}
out = map(x, 0, 1023, 0, 255); //Map the output to a PWM value
return out; //Return the value
}
void loop() {
if (analogRead(A0) < 100) {
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
analogWrite(6, pwm(analogRead(A0)));
}
if (analogRead(A0) > 700) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(6, pwm(analogRead(A0)));
}
if (analogRead(A1) < 100) {
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(9, pwm(analogRead(A1)));
}
if (analogRead(A1) > 700) {
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(9, pwm(analogRead(A1)));
}
if (analogRead(A2) < 100) {
digitalWrite(18, LOW);
digitalWrite(19, HIGH);
analogWrite(10, pwm(analogRead(A2)));
}
if (analogRead(A2) > 700) {
digitalWrite(18, HIGH);
digitalWrite(19, LOW);
analogWrite(10, pwm(analogRead(A2)));
}
if (analogRead(A3) < 100) {
digitalWrite(20, HIGH);
digitalWrite(21, LOW);
analogWrite(11, pwm(analogRead(A3)));
}
if (analogRead(A3) > 700) {
digitalWrite(20, HIGH);
digitalWrite(21, LOW);
analogWrite(11, pwm(analogRead(A3)));
}
delay(100);
}
struct
[Bearbeiten]struct Motor{
int Motornummer; // Wert 1-4 für den jeweiligen Motor
int PWM;
};
Boot II
[Bearbeiten]#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10); // (CE, CSN)
char text[0]="";
const byte address[6] = "4RF24";
void setup() {
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(120);
radio.openWritingPipe(address);
radio.stopListening();
// Serial.begin(9600);
}
void loop() {
// Serial.println(radio.isChipConnected());
if (analogRead(1)>700){
char text[]="w";
radio.write(&text, sizeof(text));
}
if (analogRead(1)<100){
char text[]="s";
radio.write(&text, sizeof(text));
}
else{
if(analogRead(0)>700){
char text[]="d";
radio.write(&text, sizeof(text));
}
if (analogRead(0)<100){
char text[]="a";
radio.write(&text, sizeof(text));
}
delay(10);
}
}
#include <SPI.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(9, 10); // (CE, CSN)
Servo servoA;
Servo servoB;
const byte address[6] = "4RF24";
void setup() {
// Serial.begin(115200);
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(120);
radio.openReadingPipe(0,address);
radio.startListening();
pinMode(2,OUTPUT);
pinMode(4,OUTPUT);
servoA.attach(3);
servoB.attach(5);
servoA.write(90);
servoB.write(90);
}
void loop() {
// Serial.println(code);
if(radio.available()){
char text[2] = {0};
radio.read(&text, sizeof(text)-1);
String code = String(text); // Array -> Zeichen ("code")
if (code == "w") {
digitalWrite(2,0);
digitalWrite(4,1);
}
if (code == "s"){
digitalWrite(2,1);
digitalWrite(4,0);
}
if (code=="d"){
servoA.write(70);
servoB.write(70);
delay(500);
}
if (code=="a"){
servoA.write(110);
servoB.write(110);
delay(500);
}
}
else {
delay(30);
if (!radio.available()){
digitalWrite(2,0);
digitalWrite(4,0);
servoA.write(90);
servoB.write(90);
}}
delay(10);
}
Ruder
[Bearbeiten]#include <Servo.h>
Servo servoA;
Servo servoB;
void setup() {
pinMode(2,OUTPUT);
pinMode(4,OUTPUT);
servoA.attach(3);
servoB.attach(5);
}
void loop() {
servoA.write(90);
servoB.write(90);
delay(2000);
servoA.write(70);
servoB.write(70);
delay(2000);
servoA.write(110);
servoB.write(110);
delay(2000);
}