Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
arduino to norland test
#include "TICL.h"
#include "CBL2.h"
#include <IRremote.h>
#define r_play 0xE1447A85
#define r_stop 0xE14406F9
#define r_fwd 0xE1444AB5
#define r_rev 0xE144CA35
#define r_aud 0xE144DE21
#define r_sub 0xE1445EA1
#define r_ang 0xE1449E61
#define r_1 0xE144A25D
#define r_5 0xE144926D
#define r_9 0xE144B24D
#define BUTTON 4
#define RECV_PIN 5
IRrecv irrecv(RECV_PIN);
decode_results results;
CBL2* ticl;
// for Send()
int data_len_lsb = 20;
uint8_t rts_data[11] = { data_len_lsb, 0x00, 0x01, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t dat_data[20] = { 0x02, 0x00,
0x00, 0x82, 0x32, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x82, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
// for Get()
uint8_t req_data[11] = { 0x09, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t var_data[11] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
void print_dat() {
for (int i=0; i<data_len_lsb; i++) {
Serial.print(" 0x");
Serial.print(dat_data[i], HEX);
}
Serial.println("");
}
void set_time(int expo, int sig_dig) {
dat_data[12] = 0x80 + expo;
dat_data[13] = sig_dig << 4;
print_dat();
}
void set_dir(int left, int right) {
dat_data[4] = (dat_data[4] & 0xF0) | left;
dat_data[5] = right << 4;
//print_dat();
}
void forward() {
set_dir(2, 2);
}
void backward() {
set_dir(0, 0);
}
void spin_left() {
set_dir(2,0);
}
void spin_right() {
set_dir(0,2);
}
void dir_random() {
set_dir(random(0,3), random(0,3));
}
int move() {
int rval = 0;
rval = ticl->sendToCBL2(VarRList, rts_data, dat_data, data_len_lsb);
return rval;
}
int getr() {
int rval = 0;
int dat_len = 0;
rval = ticl->getFromCBL2(VarReal, req_data, var_data, &dat_len, 11);
return rval;
}
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
ticl = new CBL2();
ticl->begin();
ticl->setVerbosity(true, &Serial);
pinMode(INPUT, BUTTON);
digitalWrite(BUTTON, HIGH);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
switch (results.value) {
case r_play:
forward();
move();
getr();
break;
case r_stop:
backward();
move();
getr();
break;
case r_fwd:
spin_right();
move();
getr();
break;
case r_rev:
spin_left();
move();
getr();
break;
case r_1:
set_time(2, 1);
break;
case r_5:
set_time(2, 5);
break;
case r_9:
set_time(2, 9);
break;
case r_aud:
set_time(1, 1);
break;
case r_sub:
set_time(1, 5);
break;
case r_ang:
set_time(1, 9);
break;
default:
;
}
irrecv.resume(); // Receive the next value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.