vintage calculator diy mouse knob buddy for cyberpunk retro futurism
old #calculator gets new life, adding #knob action and handy number pasting all over my #computer experiences, #luxurious #oled .
#🔢 #🔣 #🎛 ##️⃣ #cyberpunk #luxurylifestyle #custompc #diycomputer #vintagecalculator #retrotech #makersgonnamake #arduino #makersmovement #retropc #retrodesign #retrofuture #vaportech #vaporware #alternateuniverse #vintagetech #diygames #vintageelectronics #repurpose #repurposed #recycledart
“source code or it didn’t happen”
There’s two sketches, the first is everything but the pong, the second is just pong.
Knob y Calc for Arduino Pro Micro / Leonardo:
/*
Woz Supposedly (greasy conversation) put a wheel in a calculator
but had to make it again be a calculator Dec 2018
Arduino calculator with keypad and LCD, and quiz Tom Tobback Oct 2017
keypad library Andrew Mascolo May 15, 2013
*/
#include <MIDIUSB.h>
#include <EEPROM.h>
#include <Keypad.h>
#include <Keyboard.h>
#include <Mouse.h>
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R2);
char junk;
byte midichannel = 0;
int cc[20];
byte ccindex;
float mem[9][4];
bool theanswer;
bool skipanswer;
float last = 0;
float first = 0;
float second = 0;
float total = 0;
boolean mult = false; // multiplication flag to avoid overflow
boolean first_decimal = false; // does the first number have a decimal point
int first_decimal_pos = 0; // how many digits after decimal point
boolean second_decimal = false; // does the second number have a decimal point
int second_decimal_pos = 0; // how many digits after decimal point
boolean last_decimal = false; // does the second number have a decimal point
int last_decimal_pos = 0;
int digits_first = 0;
int digits_second = 0;
int digits_last = 0;
char customKey;
const byte ROWS = 3;
const byte COLS = 9;
char keys[ROWS][COLS] = {
{'9', '1', '8', '7', '6', '5', '4', '3', '2'},
{'C', 'a', 'r', 'b', 'd', 'c', '.', 'e', '0'},
{'p', '=', 's', '/', '*', '-', '+', 'm', 'M'},
};
byte rowPins[ROWS] = {1, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9, 10, 18, 19, 20, 21}; //connect to the column pinouts of the keypad
#define MIDI_CC MIDI_CC_GENERAL1
// Comment this line out to disable button debounce logic.
// See http://arduino.cc/en/Tutorial/Debounce on what debouncing is used for.
#define DEBOUNCE
// Debounce time length in milliseconds
#define DEBOUNCE_LENGTH 2
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
byte outputA = 16;
byte outputB = 15;
byte pushpinF = 14;
byte mouse = 3;
byte scrl = 1;
int aState;
int aLastState;
int goC;
int bState;
int bLastState;
byte mode = 2;
bool swap;
bool mouserepeat;
bool pushskip;
bool onoff;
byte doo;
void setup() {
/* for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}*/
int keypad;
Keyboard.begin();
Mouse.begin();
delay(2000);
u8g2.begin();
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(0, 7);
u8g2.print("woz");
u8g2.setCursor(0, 14);
u8g2.print("supposedly");
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.setCursor(0, 15);
splashmtn();
// Serial.begin(9600);
randomSeed(analogRead(A0));
pinMode(0, INPUT_PULLUP);
pinMode (outputA, INPUT_PULLUP);
pinMode (outputB, INPUT_PULLUP);
pinMode (pushpinF, INPUT_PULLUP);
customKeypad.addEventListener(keypadEvent); //add an event listener for this keypad
customKeypad.setHoldTime(1000);
}
void loop() {
/* if(digitalRead(pushpinF) == HIGH && pushskip){
pushskip=false;
}*/
//was 3000
for (int x; x < 4000; x++) {
mouseMode();
}
onoff = digitalRead(0);
customKey = customKeypad.getKey();
// normal calculator
switch (customKey)
{
case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
if (mode == 0) {
int morenotes = customKey - '0' + 60 + (!onoff * 10);
noteOn(0, morenotes, 64); // Channel 0, middle C, normal velocity
MidiUSB.flush();
delay(100);
noteOff(0, morenotes, 64); // Channel 0, middle C, normal velocity
MidiUSB.flush();
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(0, 25);
u8g2.print("note # ");
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.print(morenotes);
u8g2.setCursor(0, 15);
} else {
if (digits_first == 0) {
u8g2.clearBuffer();
u8g2.setCursor(0, 15);
}
if (digits_first < 6) {
if (first_decimal) {
first_decimal_pos++;
float divider = pow(10, first_decimal_pos);
first = first + (customKey - '0') / divider;
} else {
first = first * 10 + (customKey - '0'); // if integer (from ascii to numerical value)
}
u8g2.print(customKey);
digits_first++;
// Serial.println(first, 6);
last = first;
last_decimal = first_decimal;
digits_last = digits_first;
last_decimal_pos = first_decimal_pos;
} else { }
}
break;
case '+':
if (mode == 0) {
ccindex++;
if (ccindex > 9) {
ccindex = 0;
}
cctext();
} else {
if (digits_first == 0) {
first = last;
first_decimal = last_decimal;
digits_first = digits_last;
first_decimal_pos = last_decimal_pos;
u8g2.clearBuffer();
u8g2.setCursor(0, 15);
char buff[4];
dtostrf(last, 1, last_decimal_pos, buff);
u8g2.print(buff);
u8g2.print("+");
u8g2.sendBuffer();
second = SecondNumber();
u8g2.print("=");
total = first + second;
printTotal();
break;
}
u8g2.print("+");
u8g2.sendBuffer();
second = SecondNumber(); // get the collected the second number
if (!skipanswer) {
u8g2.print("=");
total = first + second;
printTotal();
}
skipanswer = false;
}
break;
case '-':
if (mode == 0) {
ccindex--;
if (ccindex < 0) {
ccindex = 9;
}
if (ccindex > 10) {
ccindex = 9;
}
cctext();
} else {
if (digits_first == 0) {
first = last;
first_decimal = last_decimal;
digits_first = digits_last;
first_decimal_pos = last_decimal_pos;
u8g2.clearBuffer();
u8g2.setCursor(0, 15);
char buff[4];
dtostrf(last, 1, last_decimal_pos, buff);
u8g2.print(buff);
u8g2.print("-");
u8g2.sendBuffer();
second = SecondNumber();
u8g2.print("=");
total = first - second;
printTotal();
break;
}
u8g2.print("-");
u8g2.sendBuffer();
second = SecondNumber();
if (!skipanswer) {
u8g2.print("=");
total = first - second;
printTotal();
}
skipanswer = false;
}
break;
case '*':
if (digits_first == 0) {
first = last;
first_decimal = last_decimal;
digits_first = digits_last;
first_decimal_pos = last_decimal_pos;
u8g2.clearBuffer();
u8g2.setCursor(0, 15);
char buff[4];
dtostrf(last, 1, last_decimal_pos, buff);
u8g2.print(buff);
u8g2.print("*");
u8g2.sendBuffer();
second = SecondNumber();
if (!skipanswer) {
u8g2.print("=");
total = first * second;
printTotal();
}
skipanswer = false;
break;
}
u8g2.print("*");
u8g2.sendBuffer();
mult = true;
second = SecondNumber();
if (!skipanswer) {
u8g2.print("=");
total = first * second;
printTotal();
}
skipanswer = false;
mult = false;
break;
case '/':
if (digits_first == 0) {
first = last;
first_decimal = last_decimal;
digits_first = digits_last;
first_decimal_pos = last_decimal_pos;
u8g2.clearBuffer();
u8g2.setCursor(0, 15);
char buff[4];
dtostrf(last, 1, last_decimal_pos, buff);
u8g2.print(buff);
u8g2.print("/");
u8g2.sendBuffer();
second = SecondNumber();
u8g2.print("=");
second == 0 ? u8g2.print("0") : total = (float)first / (float)second;
printTotal();
break;
}
u8g2.print("/");
u8g2.sendBuffer();
second = SecondNumber();
u8g2.print("=");
second == 0 ? u8g2.print("0") : total = (float)first / (float)second;
printTotal();
break;
case '.': if (digits_first == 0) {
break;
}
if (first_decimal) { // already has decimal point
} else {
u8g2.setCursor(digits_first * 10, 15); // add decimal point
u8g2.print(customKey); digits_first++; first_decimal = true;
} break;
case '=':
resetC();
break;
case 's':
// keypadEvent(KeypadEvent customKey);
mouseMode();
break;
case 'C':
resetC();
if (customKey == 'C') {
if (!swap) {
swap = true;
} else {
swap = false;
}
mousetext();
}
break;
case 'c':
char buff[4];
dtostrf(last, 1, last_decimal_pos, buff);
Keyboard.print(buff);
break;
case 'p':
if (mode != 2) {
mode = 2;
} else {
mode = 1;
}
mousetext();
delay(150);
break;
case 'r':
memlook();
memprint();
break;
case 'M':
memlook();
memadd();
break;
case 'm':
memlook();
memfirst();
break;
}
u8g2.sendBuffer();
}
float SecondNumber() {
while ( 1 ) {
customKey = customKeypad.getKey();
if (customKey >= '0' && customKey <= '9') {
if (digits_second < 6) {
if ((mult && (digits_first + digits_second) < 10) || !mult) {
u8g2.print(customKey);
u8g2.sendBuffer();
if (second_decimal) {
second_decimal_pos++;
float divider = pow(10, second_decimal_pos);
second = second + (customKey - '0') / divider;
}
else {
second = second * 10 + (customKey - '0'); // if integer (from ascii to numerical value)
}
digits_second++;
// Serial.println(second, 6);
last = second;
last_decimal = second_decimal;
digits_last = digits_second;
last_decimal_pos = second_decimal_pos;
}
else {
}
}
else {
}
}
if (customKey == '=') break; //return second;
if (customKey == '.') {
if (second_decimal) { // already has decimal point
}
else {
u8g2.print(customKey);
u8g2.sendBuffer();
digits_second++;
second_decimal = true;
}
}
if (customKey == 's') {
Mouse.click();
}
if (customKey == 'C') {
resetC();
skipanswer = true;
if (!swap) {
swap = true;
} else {
swap = false;
}
mousetext();
break;
}
if (customKey == 'c') {
// char buff[sizeof(last)+last_decimal_pos];
char buff[4];
dtostrf(last, 1, last_decimal_pos, buff);
Keyboard.print(buff);
}
if (customKey == 'p') {
resetC();
if (mode != 2) {
mode = 2;
} else {
mode = 1;
}
mousetext();
}
if (customKey == 'r') {
memlook();
memprint();
theanswer = true;
resetC();
theanswer = false;
skipanswer = true;
break;
}
if (customKey == 'M') {
memlook();
memadd();
theanswer = true;
resetC();
theanswer = false;
skipanswer = true;
break;
}
if (customKey == 'm') {
memlook();
memsecond();
}
} // that while tho
return second;
} // end that crazy float sub
void resetC() {
total = 0;
digits_first = 0;
digits_second = 0;
first = 0,
second = 0; // reset values back to zero for next use
first_decimal = false;
first_decimal_pos = 0;
second_decimal = false;
second_decimal_pos = 0;
if (!theanswer) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.setCursor(0, 15);
last = 0;
last_decimal_pos = 0;
digits_last = 0;
last_decimal = 0;
// if (digitalRead(0)){
splashmtn();
// }else{
// splash();
// }
}
}
void printTotal() {
int decimalPlaces;
float temp = total;
for (decimalPlaces = 0; decimalPlaces < 7; decimalPlaces++) {
if (temp == (long)temp) break; temp *= 10.0; // Shift left one decimal digit
}
//Serial.println(total, decimalPlaces);
u8g2.setCursor(0, 33);
u8g2.print(total, decimalPlaces);
u8g2.sendBuffer();
last = total;
last_decimal_pos = decimalPlaces;
theanswer = true;
resetC();
theanswer = false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
void mousetext() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(0, 15);
if (mode == 0) {
u8g2.print("m i d i");
Mouse.release();
} else if (mode == 1) {
u8g2.print("a r r o w");
Mouse.release();
} else if (mode == 2) {
u8g2.print("m o u s e");
Keyboard.releaseAll();
}
else if (mode == 3) {
u8g2.print("s c r o l l");
Keyboard.releaseAll();
Mouse.release();
}
if (!swap) {
u8g2.print(" ");
u8g2.print(char(94));
} else {
u8g2.print(" >");
}
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(80, 26);
u8g2.print("m o d e");
u8g2.sendBuffer();
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.setCursor(0, 15);
theanswer = true;
resetC();
theanswer = false;
}
void mouseMode() {
mouserepeat = false;
bool pushit;
if (onoff) {
pushit = digitalRead(pushpinF);
} else {
pushit = !digitalRead(pushpinF);
}
aState = digitalRead(outputA); // Reads the "current" state of the outputA
// If the previous and the current state of the outputA are different, that means a Pulse has occured
if (aState != aLastState) {
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
goC++;
if (goC >= 2) {
goC = 0;
if (!pushit) {
pushskip = true;
}
/// normal left rotation
if (mode == 1) {
if (!pushit) {
Keyboard.press(0x85);
}
if (swap) {
//left arrow
Keyboard.press(0xD8);
} else {
//down arrow
Keyboard.press(0xD9);
}
delay(2);
Keyboard.releaseAll();
}
if (mode == 2) {
if (!pushit) {
mouse = 24;
} else {
mouse = 3;
}
if (swap) {
Mouse.move(-mouse, 0, 0);
} else {
Mouse.move(0, mouse, 0);
}
}
if (mode == 3) {
if (!pushit) {
scrl = 2;
} else {
scrl = 1;
}
if (swap) {
Keyboard.press(0x81);
Mouse.move(0, 0, -scrl);
Keyboard.release(0x81);
} else {
Mouse.move(0, 0, -scrl);
}
}
if (mode == 0) {
// if (!pushit){scrl = 2; }else{scrl = 1;}
doo = ccindex - !onoff * 10;
if (pushit) {
cc[doo] = cc[doo] - (1 + (swap * 9));
} else {
cc[doo] = cc[doo] - (1 + (!swap * 9));
}
if (cc[doo] < 0) {
cc[doo] = 127;
}
controlChange(midichannel, doo + 30, cc[doo]);
cctext();
}
//// end normal rotation check left
}
} else {
goC--;
if (goC <= -1) {
goC = 1;
/// normal right rotation
if (mode == 1) {
if (!pushit) {
Keyboard.press(0x85);
}
if (swap) {
//right arrow
Keyboard.press(0xD7);
} else {
//up arrow
Keyboard.press(0xDA);
}
delay(2);
Keyboard.releaseAll();
}
if (mode == 2) {
if (!pushit) {
mouse = 24;
} else {
mouse = 3;
}
if (swap) {
Mouse.move(mouse, 0, 0);
} else {
Mouse.move(0, -mouse, 0);
}
}
if (mode == 3) {
if (!pushit) {
scrl = 2;
} else {
scrl = 1;
}
if (swap) {
Keyboard.press(0x81);
Mouse.move(0, 0, scrl);
Keyboard.release(0x81);
} else {
Mouse.move(0, 0, scrl);
}
}
if (mode == 0) {
// if (!pushit){scrl = 2; }else{scrl = 1;}
doo = ccindex + !onoff * 10;
if (pushit) {
cc[doo] = cc[doo] + 1 + (swap * 9);
} else {
cc[doo] = cc[doo] + 1 + (!swap * 9);
}
if (cc[doo] > 127) {
cc[doo] = 0;
}
controlChange(midichannel, doo + 30, cc[doo]);
cctext();
}
} //// end normal rotation check right
}
mouserepeat = true;
delay(4);
}
/*else // check for push if no rotate pulse
if ((!pushskip)&&(!pushit)) {
delay(150);
if(digitalRead(pushpinF) == LOW){
if (!swap) {swap=true;}else{swap=false;}
pushskip=false;
mousetext();
// delay(10);
mouserepeat = true;
}
}
*/
aLastState = aState; // Updates the previous state of the outputA with the current state
if (mouserepeat) {
mouseMode();
}
}
void splashmtn() {
int y = random(16) + 16;
int x = 0;
int siz = random(3) + 6;
while (x < 127) {
x++;
y = y + random(5) - 2;
if (y < siz + 4) {
y = siz + 4;
}
if (y > 32) {
y = 32;
}
u8g2.drawPixel(x, y);
}
x = 0;
u8g2.drawDisc(random(112) + 8, siz, siz, U8G2_DRAW_ALL);
u8g2.sendBuffer(); // transfer internal memory to the display
}
/*
void splash(){
int x;
int y;
int z;
x = random(128);
y = random(32);
z = random(10);
u8g2.drawLine(x,y,x+z,y+z);
u8g2.drawLine(x+z,y,x,y+z);
u8g2.drawCircle(random(128),random(32),random(128), U8G2_DRAW_ALL);
u8g2.drawFrame(random(128),random(32),random(32),random(16));
x = random(118)+5;
y = random(22)+5;
z = random(5);
u8g2.drawLine(x,y-z,x,y+z);
u8g2.drawLine(x-z,y,x+z,y);
x = random(100);
y = random(32);
for(int a=0;a<18;a=a+3){
u8g2.drawLine(x+a+random(12),y+a,x+a,y+a+random(12));
}
u8g2.drawLine(random(128),random(32),random(128),random(32));
// u8g2.drawCircle(random(128),random(32),random(8), U8G2_DRAW_ALL);
// u8g2.drawDisc(random(128),random(32),random(6), U8G2_DRAW_ALL);
u8g2.sendBuffer(); // transfer internal memory to the display
}
*/
void memadd() {
while ( 1 ) {
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(120, 10);
u8g2.print("S");
u8g2.setCursor(120, 17);
u8g2.print("a");
u8g2.setCursor(120, 24);
u8g2.print("v");
u8g2.setCursor(120, 31);
u8g2.print("e");
u8g2.sendBuffer();
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.setCursor(0, 15);
customKey = customKeypad.getKey();
if (customKey >= '1' && customKey <= '9') {
mem[(customKey - '0') - 1][0] = last;
mem[(customKey - '0') - 1][1] = last_decimal_pos;
mem[(customKey - '0') - 1][2] = digits_last;
mem[(customKey - '0') - 1][3] = last_decimal;
ewrite();
break;
}
if (customKey == '=' || customKey == 'C') {
resetC();
if (customKey == 'C') {
if (!swap) {
swap = true;
} else {
swap = false;
}
mousetext();
}
break;
}
delay(2);
}//
if (customKey != '=' && customKey != 'C') {
theanswer = true;
resetC();
theanswer = false;
memlook();
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.setCursor(0, 15);
}
}
void memlook() {
eread();
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(0, 32);
for (int e = 0; e < 9; e++) {
if (e == 3) {
u8g2.setCursor(0, 21);
}
if (e == 6) {
u8g2.setCursor(0, 10);
}
int decimalPlaces;
float temp = mem[e][0];
for (decimalPlaces = 0; decimalPlaces < 7; decimalPlaces++) {
if (temp == (long)temp) break; temp *= 10.0; // Shift left one decimal digit
}
u8g2.print(mem[e][0], decimalPlaces);
u8g2.print(" ");
}
u8g2.sendBuffer();
}
void memfirst() {
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(120, 8);
u8g2.print("L");
u8g2.setCursor(120, 15);
u8g2.print("o");
u8g2.setCursor(120, 22);
u8g2.print("a");
u8g2.setCursor(120, 32);
u8g2.print("d");
u8g2.sendBuffer();
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.setCursor(0, 15);
while ( 1 ) {
customKey = customKeypad.getKey();
if (customKey >= '1' && customKey <= '9') {
last = mem[(customKey - '0') - 1][0];
last_decimal_pos = mem[(customKey - '0') - 1][1];
digits_last = mem[(customKey - '0') - 1][2];
last_decimal = mem[(customKey - '0') - 1][3];
u8g2.clearBuffer();
int decimalPlaces;
float temp = last;
for (decimalPlaces = 0; decimalPlaces < 7; decimalPlaces++) {
if (temp == (long)temp) break; temp *= 10.0; // Shift left one decimal digit
}
u8g2.print(last, decimalPlaces);
u8g2.sendBuffer();
break;
}
if (customKey == '=' || customKey == 'C') {
if (customKey == 'C') {
if (!swap) {
swap = true;
} else {
swap = false;
}
mousetext();
}
resetC();
break;
}
delay(2);
}//
}
void memsecond() {
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(120, 8);
u8g2.print("L");
u8g2.setCursor(120, 15);
u8g2.print("o");
u8g2.setCursor(120, 22);
u8g2.print("a");
u8g2.setCursor(120, 32);
u8g2.print("d");
u8g2.sendBuffer();
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.setCursor(0, 15);
while ( 1 ) {
customKey = customKeypad.getKey();
if (customKey >= '1' && customKey <= '9') {
second = mem[(customKey - '0') - 1][0];
second_decimal_pos = mem[(customKey - '0') - 1][1];
digits_second = mem[(customKey - '0') - 1][2];
second_decimal = mem[(customKey - '0') - 1][3];
break;
}
if (customKey == '=' || customKey == 'C') {
break;
}
delay(2);
}//
u8g2.clearBuffer();
int decimalPlaces;
float temp = second;
for (decimalPlaces = 0; decimalPlaces < 7; decimalPlaces++) {
if (temp == (long)temp) break; temp *= 10.0; // Shift left one decimal digit
}
u8g2.print(second, decimalPlaces);
u8g2.sendBuffer();
}
void memprint() {
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(120, 9);
u8g2.print("T");
u8g2.setCursor(120, 14);
u8g2.print("y");
u8g2.setCursor(120, 23);
u8g2.print("p");
u8g2.setCursor(120, 32);
u8g2.print("e");
u8g2.sendBuffer();
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.setCursor(0, 15);
while ( 1 ) {
customKey = customKeypad.getKey();
if (customKey >= '1' && customKey <= '9') {
char buff[4];
dtostrf(mem[(customKey - '0') - 1][0], 1, mem[(customKey - '0') - 1][1], buff);
Keyboard.print(buff);
}
if (customKey == '=' || customKey == 'C') {
resetC();
if (customKey == 'C') {
if (!swap) {
swap = true;
} else {
swap = false;
}
mousetext();
}
break;
}
delay(2);
}//
}
void ewrite() {
for (int r; r < 36; r++) {
/* if (r>EEPROM.length()){
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(0, 15);
u8g2.print("mem full");
u8g2.sendBuffer();
}*/
if (r < 8) {
EEPROM.put(r * 4, mem[r][0]);
} else if (r < 18) {
EEPROM.put(r * 4, mem[r - 9][1]);
} else if (r < 18) {
EEPROM.put(r * 4, mem[r - 18][2]);
} else
{
EEPROM.put(r * 4, mem[r - 27][3]);
}
}
}
void eread() {
for (int r; r < 36; r++) {
if (r < 8) {
EEPROM.get(r * 4, mem[r][0]);
} else if (r < 18) {
EEPROM.get(r * 4, mem[r - 9][1]);
} else if (r < 18) {
EEPROM.get(r * 4, mem[r - 18][2]);
} else
{
EEPROM.get(r * 4, mem[r - 27][3]);
}
}
}
//take care of some special events
void keypadEvent(KeypadEvent customKey) {
switch (customKeypad.getState()) {
case PRESSED:
switch (customKey) {
case 's':
if (mode == 2) {
Mouse.click();
} else {
if (mode != 3) {
mode = 3;
} else {
mode = 0;
}
mousetext();
}
break;
}
break;
case RELEASED:
switch (customKey) {
case 's':
//
break;
}
break;
case HOLD:
switch (customKey) {
case 's': Mouse.click(MOUSE_RIGHT);
break;
}
break;
}
}
void cctext() {
doo = ccindex + !onoff * 10;
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x13_tr);
u8g2.setCursor(0, 25);
u8g2.print("CC");
u8g2.setFont(u8g2_font_logisoso16_tn);
u8g2.print(doo + 30);
u8g2.print(" : ");
u8g2.print(cc[doo]);
u8g2.setCursor(0, 15);
u8g2.sendBuffer();
MidiUSB.flush();
}
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}
just pong on the calc:
// Woz Supposedly of Greasy Conversation - 11-21-18
// Pong for the Knob y Calk
#include <Keyboard.h>
#include <Mouse.h>
#include <MIDIUSB.h>
#include <Adafruit_NeoPixel.h>
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R2);
#define outputA 16
#define outputB 15
#define pushpinF 14
#define mouse 3
#define scrl 1
char junk;
bool justwheel = false;
bool swap = true;
int mode = 2;
int maxBri = 255;
int aState;
int aLastState;
int goC;
int bState;
int bLastState;
int modecheck;
int mmodecheck;
int demo = 8;
int demod;
int space = 30;
int channel = 7; //starts with 0, so the real channel shows up as this number +1
int lastpatch = 0;
bool patchchange = false;
int r = 0;
int g = 0;
int b = 0;
int distchange = 33;
int dist = 0;
#define distfilter 15
int distchange2 = 33;
int dist2 = 0;
#define distfilter2 15
#define NUM_AI 6
#define ANALOGUE_PIN_ORDER A1, A3, A6, A8, A9, A0
#define MIDI_CC MIDI_CC_GENERAL1
// Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, 14, NEO_GRB + NEO_KHZ800);
#define xc 63
#define yc 16
int p1pad = 16;
int p2pad = 16;
int p1padchange = 16;
int p2padchange = 16;
int paddrift = 0;
int pspeed = 20;
int p1score = 0;
int p2score = 0;
int pballangle = 3;
int px = 16;
int py = 16;
#define pwin 9 ////----------rounds in game
#define popchance 10
#define driftchance 10
// #define bonuschance 200
// #define bonuspos 35
bool pbonus = 0;
int pvol = 0;
int pf = 1;
bool pop = false;
bool psensor = true;
bool pchill = false;
int line;
// A knob or slider movement must initially exceed this value to be recognised as an input. Note that it is
// for a 7-bit (0-127) MIDI value.
#define FILTER_AMOUNT 8
// Timeout is in microseconds
#define ANALOGUE_INPUT_CHANGE_TIMEOUT 600000
// Array containing a mapping of analogue pins to channel index. This array size must match NUM_AI above.
byte analogueInputMapping[6] = {ANALOGUE_PIN_ORDER};
byte analogueInputs[6];
byte tempAnalogueInput;
// Preallocate the for loop index so we don't keep reallocating it for every program iteration.
byte i = 0;
byte digitalOffset = 0;
// Variable to hold difference between current and new analogue input values.
byte analogueDiff = 0;
// This is used as a flag to indicate that an analogue input is changing.
boolean analogueInputChanging[6];
// Time the analogue input was last moved
unsigned long analogueInputTimer[6];
void controlChange(byte thechannel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | thechannel, control, value};
MidiUSB.sendMIDI(event);
MidiUSB.flush();
}
// void pitchBendChange(byte thechannel, int value) {
// byte lowValue = value & 0x7F;
// byte highValue = value >> 7;
// midiEventPacket_t event = {0x0E, 0xE0 | thechannel, lowValue, highValue};
// MidiUSB.sendMIDI(event);
// MidiUSB.flush();
//}
void setup() {
Keyboard.begin();
Mouse.begin();
// Serial.begin(9600); // open the serial port at 9600 bps:
delay(2000);
u8g2.begin();
pinMode (outputA, INPUT_PULLUP);
pinMode (outputB, INPUT_PULLUP);
pinMode (pushpinF, INPUT_PULLUP);
pinMode(A2, INPUT);
pinMode(A10, INPUT);
}
void mousetext() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_logisoso16_tr);
u8g2.setCursor(0, 16);
mmodecheck = analogRead(A9) / 8;
if (mmodecheck < 40) {
mode = 1;
u8g2.print("a r r o w");
} else if (mmodecheck > 80) {
mode = 3;
u8g2.print("s c r o l l");
} else {
mode = 2;
u8g2.print("m o u s e");
}
if (!swap) {
u8g2.setFont(u8g2_font_6x12_tr);
u8g2.print(" ");
u8g2.print(char(94));
} else {
u8g2.print(" >");
}
u8g2.setFont(u8g2_font_6x12_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(80, 26);
u8g2.print("m o d e");
u8g2.sendBuffer(); // transfer internal memory to the display
}
void mouseMode() {
if (digitalRead(pushpinF) == LOW) {
int mmodechange = analogRead(A9) / 32;
delay(100);
while (digitalRead(pushpinF) == LOW) {
modecheck = ((analogRead(A2) / 8) + (analogRead(A2) / 8) + (analogRead(A2) / 8)) / 3;
if (modecheck < 40) {
justwheel = true;
ledclear();
} else if (modecheck > 115) {
gameMode();
oled();
} else {
justwheel = false;
}
mousetext();
}
if ( (analogRead(A9) / 32) == mmodechange ) {
if (swap) {
swap = false;
} else {
swap = true;
}
mousetext();
}
delay(300);
}
aState = digitalRead(outputA); // Reads the "current" state of the outputA
// If the previous and the current state of the outputA are different, that means a Pulse has occured
if (aState != aLastState) {
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
goC++;
if (goC >= 2) {
goC = 0;
if (mode == 1) {
if (swap) {
//left arrow
Keyboard.write(0xD8);
} else {
//down arrow
Keyboard.write(0xD9);
}
delay(2);
}
if (mode == 2) {
if (swap) {
Mouse.move(-mouse, 0, 0);
} else {
Mouse.move(0, mouse, 0);
}
}
if (mode == 3) {
if (swap) {
Keyboard.press(0x81);
Mouse.move(0, 0, -scrl);
Keyboard.release(0x81);
} else {
Mouse.move(0, 0, -scrl);
}
}
}
} else {
goC--;
if (goC <= -1) {
goC = 1;
if (mode == 1) {
if (swap) {
//right arrow
Keyboard.write(0xD7);
} else {
//up arrow
Keyboard.write(0xDA);
}
delay(2);
}
if (mode == 2) {
if (swap) {
Mouse.move(mouse, 0, 0);
} else {
Mouse.move(0, -mouse, 0);
}
}
if (mode == 3) {
if (swap) {
Keyboard.press(0x81);
Mouse.move(0, 0, scrl);
Keyboard.release(0x81);
} else {
Mouse.move(0, 0, scrl);
}
}
}
}
delay(4);
}
aLastState = aState; // Updates the previous state of the outputA with the current state
}
void loop() {
gameMode();
//check sensor
int distcheck = (analogRead(A2) + analogRead(A2) + analogRead(A2)) / 3;
int distcheck2 = (analogRead(A10) + analogRead(A10) + analogRead(A10)) / 3;
if (distcheck < 250) {
distcheck = 0;
}
if (distcheck2 < 250) {
distcheck2 = 0;
}
if ((distcheck < distchange - distfilter) || (distcheck > distchange + distfilter)) {
if (distcheck > 1000) {
distcheck = 0;
}
dist = ((distcheck - 250) / 4);
if (dist > 127) {
dist = 127;
}
if (dist < 0) {
dist = 0;
}
int dr = dist * 5.8;
if (dr > 255) {
dr = 255;
}
int dg = (dist * 5.8) - 255;
if (dg < 0) {
dg = 0;
}
if (dg > 255) {
dg = 255;
}
int db = (dist * 5.8) - 511;
if (db > 255) {
db = 255;
}
if (db < 0) {
db = 0;
}
controlChange(channel, space + 8, dist);
distchange = distcheck;
oleddist();
} else
//check sensor 2
if ((distcheck2 < distchange2 - distfilter2) || (distcheck2 > distchange2 + distfilter2)) {
if (distcheck2 > 1000) {
distcheck2 = 0;
}
dist2 = ((distcheck2 - 250) / 4);
if (dist2 > 127) {
dist2 = 127;
}
if (dist2 < 0) {
dist2 = 0;
}
int dr2 = dist2 * 5.8;
if (dr2 > 255) {
dr2 = 255;
}
int dg2 = (dist2 * 5.8) - 255;
if (dg2 < 0) {
dg2 = 0;
}
if (dg2 > 255) {
dg2 = 255;
}
int db2 = (dist2 * 5.8) - 511;
if (db2 > 255) {
db2 = 255;
}
if (db2 < 0) {
db2 = 0;
}
controlChange(channel, space + 9, dist2);
distchange2 = distcheck2;
oleddist();
} else {
splash();
}
//void loop
}
void splash() {
demod++;
if (demod > 250) {
demod = 0;
demo++;
u8g2.clearBuffer(); // clear the internal memory
}
if (demo == 0) {
u8g2.drawPixel(random(96) + 32, random(26));
}
if (demo == 1) {
int x = random(128);
int y = random(32);
int z = random(10);
u8g2.drawLine(x, y, x + z, y + z);
u8g2.drawLine(x + z, y, x, y + z);
}
if (demo == 2) {
u8g2.drawCircle(random(128), random(32), random(8), U8G2_DRAW_ALL);
}
if (demo == 3) {
u8g2.drawFrame(random(128), random(32), random(32), random(16));
}
if (demo == 4) {
int x = random(118) + 5;
int y = random(22) + 5;
int z = random(5);
u8g2.drawLine(x, y - z, x, y + z);
u8g2.drawLine(x - z, y, x + z, y);
}
if (demo == 5) {
int x = random(128);
int y = random(32);
u8g2.drawLine(x + random(12), y, x, y + random(12));
}
if (demo == 6) {
u8g2.drawPixel(random(128), random(32));
}
if (demo == 7) {
u8g2.drawLine(random(128), random(32), random(128), random(32));
}
if (demo == 8) {
u8g2.drawCircle(random(128), random(32), random(4), U8G2_DRAW_ALL);
}
if (demo == 9) {
u8g2.setFont(u8g2_font_logisoso16_tr); // BIG NUMBERS choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 14);
u8g2.print("woz");
u8g2.setCursor(0, 28);
u8g2.print("supposedly");
demo = 0;
}
//splash end
u8g2.sendBuffer(); // transfer internal memory to the display
// delay(10);
}
void oleddist() {
if ((dist > 0) || (dist2 > 0)) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso16_tr); // BIG NUMBERS choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(9, 32);
u8g2.drawCircle(xc, yc, 5, U8G2_DRAW_ALL);
u8g2.drawCircle(xc, yc, dist2 / 12, U8G2_DRAW_LOWER_LEFT);
u8g2.drawCircle(xc, yc, dist / 12, U8G2_DRAW_LOWER_RIGHT);
u8g2.drawCircle(xc, yc, dist2 / 12 + 2, U8G2_DRAW_UPPER_LEFT);
u8g2.drawCircle(xc, yc, dist / 12 + 2, U8G2_DRAW_UPPER_RIGHT);
u8g2.drawCircle(xc, yc, dist2 / 12 + 4, U8G2_DRAW_LOWER_LEFT);
u8g2.drawCircle(xc, yc, dist / 12 + 4, U8G2_DRAW_LOWER_RIGHT);
u8g2.drawCircle(xc, yc, dist2 / 12 + 6, U8G2_DRAW_UPPER_LEFT);
u8g2.drawCircle(xc, yc, dist / 12 + 6, U8G2_DRAW_UPPER_RIGHT);
u8g2.print(dist2);
u8g2.setCursor(90, 32);
u8g2.print(dist);
}
u8g2.sendBuffer(); // transfer internal memory to the display
}
void oled() {
if (tempAnalogueInput / 8 > 0) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso16_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(10, 16);
u8g2.print(tempAnalogueInput);
u8g2.setCursor(82, 16);
u8g2.print("ch");
u8g2.print(space + i);
u8g2.drawLine(4, 3, 4, 29 );
u8g2.drawLine(1, 31 - (tempAnalogueInput / 4), 7, 31 - (tempAnalogueInput / 4) );
u8g2.drawLine(1, 32 - (tempAnalogueInput / 4), 7, 32 - (tempAnalogueInput / 4) );
u8g2.drawLine(1, 33 - (tempAnalogueInput / 4), 7, 33 - (tempAnalogueInput / 4) );
}
u8g2.sendBuffer(); // transfer internal memory to the display
}
void gametext() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x12_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 8);
if (pchill) {
u8g2.print("c h i l l ");
} else {
u8g2.print("w o z ");
}
u8g2.print("p o n g");
/* if(psensor){
u8g2.print(" air");
} */
u8g2.setFont(u8g2_font_logisoso16_tr);
u8g2.setCursor(0, 26);
}
void newround() {
pspeed = 20;
pvol = 0;
pf = 1;
pop = false;
paddrift = 0;
pbonus = 0;
}
void gameMode() {
p1score = 0;
p2score = 0;
newround();
pballangle = 3;
px = 16;
py = 16;
ledclear();
checkpin1();
p1padchange = p1pad;
while ((p1padchange > p1pad - 2) && (p1padchange < p1pad + 2)) {
gametext();
u8g2.print("player 1 start");
u8g2.sendBuffer();
checkpin1();
}
delay(200);
while (digitalRead(pushpinF)) { // while not pushing wheel---------------
//chilltest
pchill = false;
psensor = true;
delay(pspeed);
u8g2.clearBuffer(); // clear the internal memory
//move ball
if (pballangle == 1) {
px = px + pf;
py = py - 2 * pf;
}
if (pballangle == 2) {
px = px + 2 * pf;
py = py - 2 * pf;
}
if (pballangle == 3) {
px = px + 2 * pf;
py = py - pf;
}
if (pballangle == 4) {
px = px + 2 * pf;
py = py + pf;
}
if (pballangle == 5) {
px = px + 2 * pf;
py = py + 2 * pf;
}
if (pballangle == 6) {
px = px + pf;
py = py + 2 * pf;
}
if (pballangle == 7) {
px = px - pf;
py = py + 2 * pf;
}
if (pballangle == 8) {
px = px - 2 * pf;
py = py + 2 * pf;
}
if (pballangle == 9) {
px = px - 2 * pf;
py = py + pf;
}
if (pballangle == 10) {
px = px - 2 * pf;
py = py - pf;
}
if (pballangle == 11) {
px = px - 2 * pf;
py = py - 2 * pf;
}
if (pballangle == 12) {
px = px - pf;
py = py - 2 * pf;
}
if (pballangle == 13) {
px = px + 2 * pf;
}
if (pballangle == 14) {
px = px - 2 * pf;
}
//end moving
// bonuscheck();
//top bounce
if (py < 1) {
if (pballangle == 10) {
pballangle = 9;
}
if (pballangle == 11) {
pballangle = 8;
}
if (pballangle == 12) {
pballangle = 7;
}
if (pballangle == 1) {
pballangle = 6;
}
if (pballangle == 2) {
pballangle = 5;
}
if (pballangle == 3) {
pballangle = 4;
}
}
// bottom bounce
if (py > 32) {
if (pballangle == 4) {
pballangle = 3;
}
if (pballangle == 5) {
pballangle = 2;
}
if (pballangle == 6) {
pballangle = 1;
}
if (pballangle == 7) {
pballangle = 12;
}
if (pballangle == 8) {
pballangle = 11;
}
if (pballangle == 9) {
pballangle = 10;
}
}
if (paddrift > 0) {
paddrift = paddrift + 1;
if (paddrift > 30) {
paddrift = 30;
}
}
if (px < 4 + paddrift) {
volup();
if (py == p1pad - 5) {
pballangle = 1;
}
else if (py == p1pad - 4) {
pballangle = 2;
}
else if (py == p1pad - 3) {
pballangle = 2;
}
else if (py == p1pad - 2) {
pballangle = 3;
}
else if (py == p1pad - 1) {
pballangle = 3;
}
else if (py == p1pad) {
pballangle = 13;
}
else if (py == p1pad + 1) {
pballangle = 4;
}
else if (py == p1pad + 2) {
pballangle = 4;
}
else if (py == p1pad + 3) {
pballangle = 5;
}
else if (py == p1pad + 4) {
pballangle = 5;
}
else if (py == p1pad + 5) {
pballangle = 6;
}
else if (((py > p1pad + 5) || (py < p1pad - 5)) && (!pop)) {
p2score++;
if (p2score > pwin) {
p2win();
} else {
for (line = 1; line < 10; line = line + 2) {
u8g2.drawCircle(4 + paddrift, py, line, U8G2_DRAW_ALL);
delay(20);
u8g2.sendBuffer();
}
newround();
gametext();
p1miss();
}
}
if (pop) {
u8g2.clearBuffer(); // clear the internal memory
if ((py > p1pad + 5) || (py < p1pad - 5)) {
pop = false;
popsurvive();
p2miss();
paddrift = 0;
pbonus = 0;
px = 6;
} else {
popmessage();
for (line = 1; line < 100; line = line + 4) {
sparkle();
u8g2.drawCircle(4 + paddrift, py, line, U8G2_DRAW_ALL);
u8g2.sendBuffer();
}
p1score--;
p2score++;
if (p2score > pwin) {
p2win();
} else {
newround();
gametext();
p1miss();
}
}
} else {
if ((random(1, popchance) == 1) && (!pchill)) {
pop = true;
pf = 1;
}
}
if ((random(1, driftchance) == 1) && (!pchill) && (!pbonus)) {
paddrift = paddrift + 1;
}
}
if (px > 123 - paddrift) {
volup();
if (py == p2pad - 5) {
pballangle = 12;
}
else if (py == p2pad - 4) {
pballangle = 11;
}
else if (py == p2pad - 3) {
pballangle = 11;
}
else if (py == p2pad - 2) {
pballangle = 10;
}
else if (py == p2pad - 1) {
pballangle = 10;
}
else if (py == p2pad) {
pballangle = 14;
}
else if (py == p2pad + 1) {
pballangle = 9;
}
else if (py == p2pad + 2) {
pballangle = 9;
}
else if (py == p2pad + 3) {
pballangle = 8;
}
else if (py == p2pad + 4) {
pballangle = 8;
}
else if (py == p2pad + 5) {
pballangle = 7;
}
if (((py > p2pad + 5) || (py < p2pad - 5)) && (!pop)) {
p1score++;
if (p1score > pwin) {
p1win();
} else {
for (line = 1; line < 20; line = line + 4) {
u8g2.drawCircle(124 - paddrift, py, line, U8G2_DRAW_ALL);
u8g2.sendBuffer();
}
newround();
gametext();
p2miss();
}
}
if (pop) {
u8g2.clearBuffer(); // clear the internal memory
if ((py > p2pad + 5) || (py < p2pad - 5)) {
pop = false;
popsurvive();
p1miss();
paddrift = 0;
pbonus = 0;
px = 121;
} else {
popmessage();
for (line = 1; line < 200; line = line + 8) {
sparkle();
u8g2.drawCircle(px, py, line, U8G2_DRAW_ALL);
u8g2.sendBuffer();
}
p2score--;
p1score++;
if (p1score > pwin) {
p1win();
} else {
newround();
gametext();
p2miss();
}
}
} else {
if ((random(1, popchance) == 1) && (!pchill)) {
pop = true;
pf = 1;
}
}
if ((random(1, driftchance) == 1) && (!pchill) && (!pbonus)) {
paddrift = paddrift + 1;
}
}
checkpin2();
checkpin1();
u8g2.drawLine(0 + paddrift, p1pad - 2, 0 + paddrift, p1pad + 2 );
u8g2.drawLine(1 + paddrift, p1pad - 3, 1 + paddrift, p1pad + 3 );
u8g2.drawLine(2 + paddrift, p1pad - 2, 2 + paddrift, p1pad + 2 );
u8g2.drawLine(125 - paddrift, p2pad - 2, 125 - paddrift, p2pad + 2 );
u8g2.drawLine(126 - paddrift, p2pad - 3, 126 - paddrift, p2pad + 3 );
u8g2.drawLine(127 - paddrift, p2pad - 2, 127 - paddrift, p2pad + 2 );
if (pop) {
u8g2.drawCircle(px, py, 3, U8G2_DRAW_ALL);
} else {
u8g2.drawDisc(px, py, 2, U8G2_DRAW_ALL);
}
u8g2.setFont(u8g2_font_6x12_tr);
if ((p1score < 10) && (p1score > -1)) {
u8g2.setCursor(56, 10);
} else {
u8g2.setCursor(49, 10);
}
u8g2.print(p1score);
u8g2.setCursor(66, 10);
u8g2.print(p2score);
u8g2.setCursor(66, 30);
u8g2.print(pvol);
for (line = 1; line < 32; line = line + 2) {
u8g2.drawLine(63, line, 63, line);
}
u8g2.sendBuffer();
}
}
void p1miss() {
checkpin2();
p2padchange = p2pad;
u8g2.print("player 2 start");
u8g2.sendBuffer();
delay(1000);
while ((p2padchange > p2pad - 2) && (p2padchange < p2pad + 2) && digitalRead(pushpinF) == HIGH) {
checkpin2();
}
if (p2pad > p2padchange) {
pballangle = 9;
}
if (p2pad < p2padchange) {
pballangle = 10;
}
py = p2pad;
px = 121;
pop = false;
}
void p2miss() {
checkpin1();
p1padchange = p1pad;
u8g2.print("player 1 start");
u8g2.sendBuffer();
delay(1000);
while ((p1padchange > p1pad - 2) && (p1padchange < p1pad + 2) && digitalRead(pushpinF) == HIGH) {
checkpin1();
}
if (p1pad > p1padchange) {
pballangle = 4;
}
if (p1pad < p1padchange) {
pballangle = 3;
}
py = p1pad;
px = 6;
pop = false;
}
void p1win() {
u8g2.setFont(u8g2_font_logisoso16_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 16);
u8g2.print("player 1 WINS");
ledclear();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso16_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 16);
u8g2.print(p1score);
u8g2.setCursor(22, 16);
u8g2.print("< winner");
u8g2.setCursor(109, 16);
u8g2.print(p2score);
u8g2.setFont(u8g2_font_6x12_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 30);
u8g2.print("now player 2 starts");
u8g2.sendBuffer();
delay(3000);
checkpin2();
p2padchange = p2pad;
while ((p2padchange > p2pad - 2) && (p2padchange < p2pad + 2) && (digitalRead(pushpinF) == HIGH)) {
sparkle();
checkpin2();
}
if (p2pad > p2padchange) {
pballangle = 9;
}
if (p2pad < p2padchange) {
pballangle = 10;
}
ledclear();
py = p2pad;
px = 124;
p1score = 0;
p2score = 0;
newround();
}
void p2win() {
u8g2.setFont(u8g2_font_logisoso16_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 16);
u8g2.print("player 2 WINS");
ledclear();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_logisoso16_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 16);
u8g2.print(p1score);
u8g2.setCursor(22, 16);
u8g2.print("winner >");
u8g2.setCursor(109, 16);
u8g2.print(p2score);
u8g2.setFont(u8g2_font_6x12_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 30);
u8g2.print("now player 1 starts");
u8g2.sendBuffer();
delay(3000);
checkpin1();
p1padchange = p1pad;
while ((p1padchange > p1pad - 2) && (p1padchange < p1pad + 2) && (digitalRead(pushpinF) == HIGH)) {
sparkle();
checkpin1();
}
if (p1pad > p1padchange) {
pballangle = 4;
}
if (p1pad < p1padchange) {
pballangle = 3;
}
ledclear();
py = p1pad;
px = 4;
p1score = 0;
p2score = 0;
newround();
}
void checkpin1() {
if (psensor) {
int distcheck2 = (analogRead(A10) + analogRead(A10) + analogRead(A10)) / 3;
if (distcheck2 < 175) {
distcheck2 = 0;
}
if ((distcheck2 < distchange2 - distfilter2) || (distcheck2 > distchange2 + distfilter2)) {
if (distcheck2 > 1000) {
distcheck2 = 0;
}
dist2 = ((distcheck2 - 175) / 4.25);
if (dist2 > 127) {
dist2 = 127;
}
if (dist2 < 0) {
dist2 = 0;
}
}
p1pad = (dist2 / 5) + 3;
} else {
p1pad = ((33 - (analogRead(A8) / 34)) + (33 - (analogRead(A8) / 34)) + (33 - (analogRead(A8) / 34))) / 3;
}
}
void checkpin2() {
if (psensor) {
int distcheck = (analogRead(A2) + analogRead(A2) + analogRead(A2)) / 3;
if (distcheck < 175) {
distcheck = 0;
}
if ((distcheck < distchange - distfilter) || (distcheck > distchange + distfilter)) {
if (distcheck > 1000) {
distcheck = 0;
}
dist = ((distcheck - 175) / 4.25);
if (dist > 127) {
dist = 127;
}
if (dist < 0) {
dist = 0;
}
}
p2pad = (dist / 5) + 3;
} else {
p2pad = ((33 - (analogRead(A2) / 34)) + (33 - (analogRead(A2) / 34)) + (33 - (analogRead(A2) / 34))) / 3;
}
}
void ledclear() {
/* for(int l=0; l<8; l++){
strip.setPixelColor(l, strip.Color(0,0,0));
}
strip.show(); */
}
void sparkle() {
/* int yeah = random(7);
strip.setPixelColor(yeah, strip.Color(255,255,255));
strip.show();
delay(10);
strip.setPixelColor(yeah, strip.Color(0,0,0));
strip.show();
*/
}
void winblast() {
/*
int dr = line*7.5;
if(dr>255){dr=255;}
int dg = (line*7.5)-255;
if(dg<0){dg=0;}
if(dg>255){dg=255;}
int db = (line*7.5)-511;
if(db>255){db=255;}
if(db<0){db=0;}
for(int l=0; l<5; l++){
strip.setPixelColor(l, strip.Color(dr,dg,db));
}
strip.show();
delay(10);
*/
}
void popmessage() {
u8g2.setFont(u8g2_font_logisoso16_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 16);
u8g2.print("exploding ball!");
}
void popsurvive() {
u8g2.setFont(u8g2_font_6x12_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2.setCursor(0, 8);
u8g2.print("you survived!");
u8g2.setFont(u8g2_font_logisoso16_tr);
u8g2.setCursor(0, 26);
}
void volup() {
if ((pvol > 4) && (!pchill)) {
pf = (pvol / 4);
}
pspeed--;
if (pspeed < 0) {
pspeed = 0;
}
pvol++;
}