Commit f45e972b authored by Richard Benson's avatar Richard Benson

Initial commit

parents
This license applies to all code in this repository except where otherwise specified
-----
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
#include <Arduino.h>
//#include <avr/pgmspace.h>
#define OUT1 4
#ifndef DELAY
#define DELAY 500
#endif
void setup () {
uint8_t cl;
for (cl = OUT1; cl < (OUT1 + 4); cl ++) {
pinMode (cl, OUTPUT);
digitalWrite (cl, LOW);
}
for (;;) {
for (cl = 0; cl < 8; cl ++) {
digitalWrite (OUT1, cl & 1);
digitalWrite (OUT1 + 1, cl & 2);
digitalWrite (OUT1 + 2, cl & 4);
delay (DELAY);
}
}
}
void loop () {
}
#include <Arduino.h>
//#include <avr/pgmspace.h>
#define DEBUG 1
#define BUF_N 80
char in_b[BUF_N];
char out_b[BUF_N];
uint8_t in_c = 0;
#define NL 8
const uint8_t PINS[] = { 8, 9, 10, 5, 4, 7, 6, 11 };
const uint8_t BITS[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
#define NC 36
const uint8_t CODE[NC] = {
// DIGITS
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
0x7f, 0x6f,
// A-F
0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71,
// G-Z
0x3d, 0x76, 0x30, 0xe, 0x72, 0x38, 0x55, 0x54,
0x5c, 0x73, 0x67, 0x50, 0x6c, 0x31, 0x3e, 0x1c,
0x49, 0x52, 0x6a, 0x1b
};
uint16_t DELAY1 = 500;
uint16_t DELAY2 = 100;
uint16_t DELAY3 = 200;
volatile uint8_t but = 0;
void ss_print_binary (const char *s) {
for (auto m = (char *)s; *m; m ++) {
for (auto cl = 0; cl < NL; cl ++) {
digitalWrite (PINS[cl], *m & BITS[cl]);
}
delay (DELAY1);
for (auto cl = 0; cl < NL; cl++)
digitalWrite (PINS[cl], LOW);
delay (DELAY2);
}
delay (DELAY3);
}
void ss_print_string (const char *s) {
uint8_t c;
for (auto m = (char *)s; *m; m ++) {
if ((*m >= '0') && (*m <= '9'))
c = *m - '0';
else if ((*m >= 'a') && (*m <= 'z'))
c = *m - 'a' + 10;
else if ((*m >= 'A') && (*m <= 'Z'))
c = *m - 'A' + 10;
else
continue;
for (auto cl = 0; cl < NL; cl ++)
digitalWrite (PINS[cl], (CODE[c] & BITS[cl]));
delay (DELAY1);
for (auto cl = 0; cl < NL; cl++)
digitalWrite (PINS[cl], LOW);
delay (DELAY2);
}
Serial.println (s);
delay (DELAY3);
}
void ss_print_chars (void) {
for (auto w = 0; w < NC; w ++) {
for (auto cl = 0; cl < NL; cl ++)
digitalWrite (PINS[cl], (CODE[w] & BITS[cl]));
delay (10);
}
for (auto cl = 0; cl < NL; cl++)
digitalWrite (PINS[cl], LOW);
delay (DELAY3);
}
void interp (const char *s) {
uint16_t i16a, i16b;
uint8_t l;
char *m, *m2;
l = strlen (s);
if (l < 2)
goto ERR;
switch (*s) {
case 'P':
case 'p':
m = strchr (s, ' ');
if (! m)
goto ERR;
m ++;
if (! *m)
goto ERR;
ss_print_string (m);
return;
break;
case 'A':
case 'a':
m = strchr (s, ' ');
if (! m)
goto ERR;
m ++;
if (! *m)
goto ERR;
m2 = strchr (m, ' ');
if (! m2)
goto ERR;
m2 ++;
if (! *m2)
goto ERR;
i16a = atoi (m);
i16b = atoi (m2);
sprintf (out_b, "%d", i16a + i16b);
ss_print_string (out_b);
return;
break;
}
ERR:
ss_print_string ("ERR");
}
void on_button () {
but = 1;
}
void setup () {
Serial.begin (9600);
for (auto cl = 0; cl < NL; cl ++) {
pinMode (PINS[cl], OUTPUT);
digitalWrite (PINS[cl], LOW);
}
pinMode (2, INPUT);
digitalWrite (2, LOW);
attachInterrupt (0, on_button, RISING);
//randomSeed (analogRead (0));
ss_print_chars ();
ss_print_string ("RD");
}
void loop () {
auto a = Serial.available ();
while (a--) {
auto r = Serial.read ();
if ((r == '\r') || (in_c == (BUF_N -1))) {
in_b [in_c] = 0;
in_c = 0;
Serial.write ("\r\n");
interp (in_b);
ss_print_string ("RD");
return;
}
else if (r == '\n') {
return;
}
in_b [in_c ++] = r;
Serial.write (r);
}
if (but) {
but = 0;
ss_print_string ("HI");
}
}
all: a2enc
clean:
rm -f a2enc
#include <stdlib.h>
#include <stdio.h>
#define IN_N 1024
int main () {
unsigned char bin[IN_N], *m;
unsigned char e;
while (fgets (bin, IN_N, stdin)) {
e = 0;
for (m = bin; *m; m++)
switch (*m) {
case 'A': e |= 1; break;
case 'B': e |= 2; break;
case 'C': e |= 4; break;
case 'D': e |= 8; break;
case 'E': e |= 16; break;
case 'F': e |= 32; break;
case 'G': e |= 64; break;
case 'H': e |= 128; break;
}
printf ("0x%x\n", e);
}
return 0;
}
ACDEF
BCEFG
EF
BCD
BEFG
DEF
ACEG
CEG
CDEG
ABEFG
ABCFG
EG
CDFG
AFE
BCDEF
CDE
ADG
BEG
BDFG
ABDE
// ArduinoNunchuk.cpp - Improved Wii Nunchuk library for Arduino
// Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
// Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
//// mod by richardbenson91477@gmail.com 1/30/18
#include <Arduino.h>
#include <Wire.h>
#include "Nunchuk_idm.h"
// class static
void Nunchuk::init () {
Wire.begin ();
Nunchuk::send (0x55, 0xF0);
Nunchuk::send (0x00, 0xFB);
}
// class static
void Nunchuk::send (uint8_t data, uint8_t loc) {
Wire.beginTransmission (Nunchuk::i2c_addr);
Wire.write (loc);
Wire.write (data);
Wire.endTransmission ();
delay (10);
}
void Nunchuk::update () {
int vals [6];
int c = 0;
Wire.requestFrom (Nunchuk::i2c_addr, 6);
while (Wire.available ()) {
// vals[c] = Wire.receive ();
vals[c] = Wire.read ();
// ? vals[c] = 0x17 + (0x17 ^ vals[c];
c ++;
}
this->ax = vals[0];
this->ay = vals[1];
this->rx = (vals[2] << 2) | ((vals [5] >> 2) & 3);
this->ry = (vals[3] << 2) | ((vals [5] >> 4) & 3);
this->rz = (vals[4] << 2) | ((vals [5] >> 6) & 3);
this->z = !(vals[5] & 1);
this->c = !(vals[5] & 2);
Nunchuk::send (0x00, 0x00);
}
// ArduinoNunchuk.cpp - Improved Wii Nunchuk library for Arduino
// Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
// Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
//// mod by richardbenson91477@gmail.com 1/30/18
#ifndef NUNCHUK_IDM_H
#define NUNCHUK_IDM_H
#include <Arduino.h>
class Nunchuk {
public:
static void init ();
static void send (uint8_t data, uint8_t loc);
void update ();
int ax, ay;
int rx, ry, rz;
int z, c;
static const char i2c_addr = 0x52;
};
#endif
// DigiJoystick Nunchuck Demo
#include <DigiJoystick.h>
#include <Nunchuk_idm.h>
Nunchuk nck = Nunchuk ();
void setup () {
Nunchuk::init ();
}
void loop () {
nck.update ();
DigiJoystick.setX ((byte) nck.ax);
DigiJoystick.setY ((byte) nck.ay);
DigiJoystick.setXROT ((byte) map(nck.rx,255,700,0,255));
DigiJoystick.setYROT ((byte) map(nck.ry,255,850,0,255));
DigiJoystick.setZROT ((byte) map(nck.rz,255,750,0,255));
int buttonByte = 0;
bitWrite (buttonByte, 0, nck.z);
bitWrite (buttonByte, 1, nck.c);
DigiJoystick.setButtons ((byte) buttonByte, (byte) 0);
DigiJoystick.delay (10);
}
../../../builder-digispark.mak
\ No newline at end of file
// Digispark Nunchuck shield demo
#include <Nunchuk_idm.h>
#include <DigiUSB.h>
#include <Wire.h>
Nunchuk nck = Nunchuk ();
void setup () {
DigiUSB.begin ();
Nunchuk::init ();
}
void loop () {
nck.update ();
DigiUSB.println (nck.ax, DEC);
DigiUSB.println (nck.ay, DEC);
DigiUSB.println (nck.rx, DEC);
DigiUSB.println (nck.ry, DEC);
DigiUSB.println (nck.rz, DEC);
DigiUSB.println (nck.z, DEC);
DigiUSB.println (nck.c, DEC);
DigiUSB.delay (250);
}
../../../builder-digispark.mak
\ No newline at end of file
// based originally on:
// SSD1306xLED - Drivers for SSD1306 controlled dot matrix OLED/PLED 128x64
// author: Neven Boyanov
// richardbenson91477@gmail.com 1/30/18
#include <Arduino.h>
#include "OLED_idm.h"
#include "SSD1306_init_seq.h"
void OLED::begin () {
uint8_t *pseq = (uint8_t *) SSD1306_init_seq;
Wire.begin ();
for (uint8_t i = 0; i < sizeof(SSD1306_init_seq); i++) {
Wire.beginTransmission (OLED::i2c_addr);
Wire.write (0x00);
Wire.write (pgm_read_byte (pseq ++));
Wire.endTransmission ();
}
// NOTE: modify this to 132 for SH1106
this->res_x = 128;
this->res_yp = 8;
}
void OLED::cursor_set (uint8_t x, uint8_t yp) {
this->cur_x = x;
this->cur_yp = yp;
cursor_go ();
}
void OLED::cursor_go () {
Wire.beginTransmission (OLED::i2c_addr);
Wire.write (0x00);
Wire.write (0xb0 + this->cur_yp);
Wire.write (0x10 + (this->cur_x >> 4));
Wire.write (this->cur_x & 0x0f);
Wire.endTransmission ();
}
void OLED::fill (uint8_t fill) {
uint16_t bs = this->res_x * this->res_yp;
uint8_t bdiv = bs / OLED::i2c_buf_s,
brem = bs % OLED::i2c_buf_s;