Forum: Mikrocontroller und Digitale Elektronik Mit dem Mega2560 und kRPC Kerbal Space steuern.


von Peter B. (funkheld)


Angehängte Dateien:

Lesenswert?

Mit dem Mega2560 und einem Keypad kann  man das Programm "Kerbal Space " 
steuern.
Hier der Mega2560-Code für Throttle und Stage :
1
#include <Keypad.h>
2
 
3
const byte numRows= 4; 
4
const byte numCols= 4; 
5
char keymap[numRows][numCols]= 
6
{
7
  {'0', '4', '8', 'C'}, 
8
  {'1', '5', '9', 'D'}, 
9
  {'2', '6', 'A', 'E'},
10
  {'3', '7', 'B', 'F'}
11
};
12
 
13
byte rowPins[numRows] = {53,51,49,47}; //Rows 0 to 3
14
byte colPins[numCols]= {45,43,41,39}; //Columns 0 to 3
15
byte inbyte;
16
byte throttle_p;
17
byte throttle_m;
18
byte stage;
19
 
20
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
21
 
22
void setup()
23
{
24
  Serial2.begin(9600);
25
  Serial.begin(9600); 
26
  
27
  throttle_p=1;
28
  throttle_m=2;
29
  stage=3;
30
}
31
 
32
void loop()
33
{
34
  char keypressed = myKeypad.getKey();
35
36
  if (Serial2.available()){
37
    inbyte = Serial2.read();
38
    Serial.write(inbyte);
39
  }
40
  
41
  if (keypressed =='0') {
42
    Serial2.print(throttle_p);
43
  } 
44
  if (keypressed =='1') {
45
    Serial2.print(throttle_m);
46
  } 
47
  if (keypressed =='2') {
48
    Serial2.print(stage);
49
  } 
50
  
51
}

von Thomas L. (thomas_hx)


Lesenswert?

Es heisst "Kerbal Space Program", so viel Zeit muss sein. ;-)

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.