So, mit etwas einlesen hab ich es zumindest so weit das es sich kompilieren lässt.
Am Wochenende mal probieren ob da was vernünftiges rauskommt.
Könnte man ansonsten schon mal was verbessern? Gerade in Bezug auf die Delays, es soll ja später nebenbei auch noch was anderes laufen.
#include <util/delay.h>
// pin that connects to the Heng Long main board
int RXPin = 7;
// Heng Long tank bit-codes
int idle = 0xFE40121C;
int ignition = 0xFE401294;
int left_slow = 0xFE400608;
int left_fast = 0xFE400010;
int right_slow = 0xFE401930;
int right_fast = 0xFE401E2C;
int fwd_slow = 0xFE200F34;
int fwd_fast = 0xFE000F3C;
int rev_slow = 0xFE580F08;
int rev_fast = 0xFE780F00;
int turret_left = 0xFE408F0C;
int turret_right = 0xFE410F28;
int turret_elev = 0xFE404F3C;
int fire = 0xFE442F34;
int machine_gun = 0xFE440F78;
int recoil = 0xFE420F24;
int i;
char inchar;
// Function declarations
void sendCode(int code);
void sendBit(int bit);
void setup() // run once, when the sketch starts
{
pinMode(RXPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
// Send the idle and ignition codes
digitalWrite(RXPin, LOW);
Serial.println("Idle");
for (i=0; i<40; i++)
{
sendCode(idle);
}
Serial.println("Ignition");
for (i=0; i<10; i++)
{
sendCode(ignition);
}
Serial.println("Waiting for ignition");
for (i=0; i<300; i++)
{
sendCode(idle);
}
}
void loop() // run over and over again
{
if (Serial.available() > 0) {
// Loop, sending movement commands indefinitely
do {
Serial.println("Ready: ");
inchar = Serial.read();
if (inchar == 'w') {
Serial.println("Forward");
for (i=0; i<100; i++)
{
sendCode(fwd_fast);
}
sendCode(idle);
}
else if (inchar == 's') {
Serial.println("Reverse");
for (i=0; i<100; i++)
{
sendCode(rev_fast);
}
sendCode(idle);
}
else if (inchar == 'a') {
Serial.println("Left");
for (i=0; i<10; i++)
{
sendCode(left_fast);
}
sendCode(idle);
}
else if (inchar == 'd') {
Serial.println("Right");
for (i=0; i<10; i++)
{
sendCode(right_fast);
}
sendCode(idle);
}
else if (inchar == 'q') {
Serial.println("Turret Left");
for (i=0; i<25; i++)
{
sendCode(turret_left);
}
sendCode(idle);
}
else if (inchar == 'e') {
Serial.println("Turret Right");
for (i=0; i<25; i++)
{
sendCode(turret_right);
}
sendCode(idle);
}
else if (inchar == 'z') {
Serial.println("Turret Elev");
for (i=0; i<50; i++)
{
sendCode(turret_elev);
}
sendCode(idle);
}
else if (inchar == 'x') {
Serial.println("Fire");
for (i=0; i<50; i++)
{
sendCode(fire);
}
sendCode(idle);
}
} while (inchar != '.');
Serial.println("Ignition Off");
for (i=0; i<10; i++)
{
sendCode(ignition);
}
Serial.println("Idle");
for (i=0; i<40; i++)
{
sendCode(idle);
}
return;
}
}
// Sends one individual code to the main tank controller
void sendCode(int code) {
// Send header "bit" (not a valid Manchester code)
digitalWrite(RXPin, HIGH);
_delay_us(500);
// Send the code itself, bit by bit using Manchester coding
int i;
for (i=0; i<32; i++) {
int bit = (code>>(31-i)) & 0x1;
sendBit(bit);
}
// Force a 4ms gap between messages
digitalWrite(RXPin, LOW);
_delay_us(3333);
} // sendCode
// Sends one individual bit using Manchester coding
// 1 = high-low, 0 = low-high
void sendBit(int bit) {
// Serial.println("%d", bit);
if (bit == 1) {
digitalWrite(RXPin, HIGH);
_delay_us(250);
digitalWrite(RXPin, LOW);
_delay_us(250);
} else {
digitalWrite(RXPin, LOW);
_delay_us(250);
digitalWrite(RXPin, HIGH);
_delay_us(250);
}
} // sendBit