Projekt:Tüftlerclub/Werkstatt
Erscheinungsbild
Bjarne
[Bearbeiten]- Omnibit mit Servo-Kanone
- Makecode
Lijo
[Bearbeiten]Funk
[Bearbeiten]Pneumatik: Ventil mit Servo schalten
[Bearbeiten]#include <Servo.h>
Servo myservoA;
void setup() {
myservoA.attach(9);
}
void loop() {
myservoA.write(30);
delay(2000);
myservoA.write(50);
delay(2000);
myservoA.write(65);
delay(2000);
myservoA.write(50);
delay(2000);
}
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);
}