change Arduino pins to 2, 3, 4, 5, remove old serial code, update builder's manual

This commit is contained in:
ohsqueezy 2023-01-25 16:09:07 -05:00
parent 4a076a72d0
commit dcef09e613
9 changed files with 57 additions and 376 deletions

View File

@ -3,7 +3,7 @@ Code
Original source code is released under the zlib license:
Copyright (c) 2018 Frank DeMarco, Blake Andrews, and Dr. Clement Shimizu <scrape@nugget.fun>
Copyright (c) Frank DeMarco, Blake Andrews, and Dr. Clement Shimizu <scrape@nugget.fun>
This software is provided 'as-is', without any express or implied warranty. In
no event will the authors be held liable for any damages arising from the use of

4
NS.py
View File

@ -6,7 +6,7 @@
# the hardware. For more information on setting up and running the game, see
# README.md, or for the game in general, visit <https://scrape.nugget.fun/>.
#
# Full open source code is available at <https://git.nugget.fun/scrape/scrapeboard>.
# Full open source code is available at <https://open.shampoo.ooo/scrape/scrapeboard>.
#
# This is the main file containing all the pygame code.
@ -517,7 +517,7 @@ class NS(Game, Animation):
elif self.serial_enabled():
# Translate the most recent serial data, being provided by serial/serial2/serial2.ino, into pad states
# Translate the most recent serial data, being provided by serial/serial.ino, into pad states
self.apply_serial()
# Handle auto reset of the Arduino for stablizing serial data

View File

@ -109,7 +109,7 @@ See [LICENSE.txt][]
Contact
-------
Email us at scrape (at) nugget (dot) fun
More information is available [at the website](https://scrape.nugget.fun). Email us at scrape (at) nugget (dot) fun.
Donations
---------
@ -120,7 +120,7 @@ Send us a donation through [Ko-fi](https://ko-fi.com/scrapeboard)!
[Pygame]: https://pygame.org
[Makey Makey]: https://makeymakey.com
[serial program]: serial/serial2/serial2.ino
[serial program]: serial/serial.ino
[pyserial]: https://pypi.org/project/pyserial/
[Arduino]: https://arduino.cc
[config file]: config

View File

@ -1,35 +1,39 @@
Scrapeboard Builder's Manual
============================
Scrapeboard is an alternative controller game that uses a skateboard deck and metal floor pads for input. The goal is to do combinations of moves in series as quickly as possible. This manual covers how to build a full Scrapeboard system. It includes how to install and test the software, how to build the electronics, and how to fabricate a controller using a skateboard deck, metal pads and plywood.
![demo](https://scrape.nugget.fun/www/Scrapeboard_Gameplay_Demo_picture_in_picture.webp)
Scrapeboard is an alternative controller game that uses a skateboard deck and metal floor pads for input. In the game, the player is a lizard who is given a skatedeck by Tony Hawk and challenged to swords matches with a series of goons. The object of each match is to perform combinations of moves displayed on screen as quickly as possible.
The game is available to play at select game conventions and festivals, but it is also a D.I.Y. project that is not difficult to reproduce. This manual covers how to build a full Scrapeboard system. It includes how to install and test the software, how to build the electronics, and how to fabricate a controller using a skateboard deck, metal pads, and plywood.
Audience
--------
It is intended for a general audience. No coding, electronics, or fabrication experience is required.
It is intended for a general audience. There are steps that involve beginner level electronics and wood working. The instructions assume a bit of understanding about how to connect components when using the Arduino. There are steps that require the use of a drill.
Purpose
-------
The builder's manual was created so more Scrapeboard systems can be built, whether by the core team or other members of the community. With their own Scrapeboard system, players can challenge themselves and their friends outside of events and host their own events. It is released with open licensing so that the finished system is free to be used in any context, including being modified or used commercially in an arcade or bar.
The builder's manual was created so players could build Scrapeboard on their own and challenge themselves and friends outside of events and host their own events. It is released with open licensing, so the finished system can be used for personal use, for example in a player's garage or basement, or commercial, like in an arcade or bar. It is also licensed to be modified, so the controller can be used for other games, including custom ones. With more Scrapeboard systems, whether built by the core team or other members of the community, access to Scrapeboard outside of occasional events can be made possible.
License
-------
The code, electronics, and manual are released as open source, so the system is licensed to be modified and used for any purpose, including commercial. See [LICENSE.txt](../LICENSE.txt) for details.
Introduction
------------
History
-------
Scrapeboard started in 2017 as a side project of the exhibition STORE 2 at Babycastles, which Frank, Blake, and Clement, the creators of Scrapeboard, worked together on, along with curator Mushbuh and a team of volunteers. The team received a donation of a signed skatedeck from Tony Hawk to be added to the exhibition. After the exhibition, in preparation for MAGFest 2018, Frank and Blake decided, in the tradition of Babycastles, to turn the skatedeck into a game controller with the basic concept of making something similar to Dance Dance Revolution but using a skatedeck instead of the player's feet for input.
Scrapeboard started in 2017 as a side project of the STORE 2 exhibition at [Babycastles](https://babycastles.com), which Frank, Blake, and Clement, the creators of Scrapeboard, worked on, along with curator Mushbuh and a team of volunteers. The team received a donation of a signed skatedeck from Tony Hawk to be added to the exhibition. After the exhibition, in preparation for [MAGFest](https://super.magfest.org) 2018, Frank and Blake turned the skatedeck into a game controller with the idea of making something similar to Dance Dance Revolution, using a skatedeck instead of the player's feet for input.
The original prototype was created using the skatedeck, cardboard, aluminum foil, copper tape, and a Makey Makey. The skatedeck was turned into a conductive device by applying copper tape to the bottom of the deck and placing it on a platform made of cardboard and layered aluminum foil. In the center of the platform was a cross section of aluminum foil, separated from four other sections of aluminum foil outside the cross section. The four outside sections and cross section were connected to the Makey Makey with alligator clips. This served as a proof of concept for the game and even lasted through multiple events.
The original prototype was created using the signed skatedeck, cardboard, aluminum foil, copper tape, and a Makey Makey. The skatedeck was turned into a conductive device by applying copper tape to the bottom of the deck and placing it on a platform made of cardboard and layered aluminum foil. In the center of the platform was a cross section of aluminum foil, separated by bare cardboard and painter's tape from four other sections of aluminum foil outside the cross section. The four outside sections and cross section were connected to the Makey Makey with alligator clips. This served as a proof of concept for the game and even was able to be used for a few events.
The next version of Scrapeboard used four aluminum street signs, a rug, an aluminum sheet, and an Arduino. Four rectangles were cut into the rug to frame the aluminum signs, which were taped to the bottom of the rug with carpet tape. The aluminum sheet was drilled into the bottom of the signed skatedeck. The Arduino circuit was designed using pull-up resistors and a program loop which turned each input low each loop so that it didn't require a ground connection anymore. This version was used for a few years for many events but required a lot of repair and maintenance before and after each event.
The next version of Scrapeboard used four aluminum street signs, a rug, an aluminum sheet, and an Arduino. Four rectangles were cut into the rug to frame the aluminum signs, which were taped to the bottom of the rug with carpet tape. The aluminum sheet was drilled into the bottom of the signed skatedeck. The Arduino circuit was designed using pull-up resistors and a program loop which turned each input low and tested for a connection with the other inputs, so the circuit wouldn't require a ground connection anymore. This version was used for many events but required a lot of repair and maintenance before and after each event.
A newer model was made in preparation for GDC 2022, using wood, aluminum street signs, steel anchor rings, and the same Arudino circuit. The aluminum street signs were drilled into four pieces of wood which were bracketed together on the underside. The steel anchor rings were fastened to the underside of the skatedeck using machine screws. By the end of 2022, this version had been refined to the point where it could last multiple events without needing repair, a significant milestone for the project because it opened up the possibility of the game being able to run without constant supervision.
A newer model was made in preparation for GDC 2022, using wood, aluminum street signs, steel anchor rings, and the same Arudino circuit. The aluminum street signs were drilled into four pieces of wood which were bracketed together on the underside. The steel anchor rings were fastened to the underside of the skatedeck using machine screws. By the end of 2022, this version had been refined to the point where it could last through multiple events without needing repair, a significant milestone for the project because it opened up the possibility of the game being able to run without constant supervision.
Although there are still improvements being worked on, the 2022 model is what this manual is based on and what the instructions will create if the optional sections are skipped. Since that model has proven to be relatively durable, we can recommend the steps to reproduce it as a simple method for Scrapeboard players to construct a system of their own. Further improvements are covered by optional steps and more will likely be added in the future.
Although there are still improvements being worked on, the 2022 model is what this manual is based on and what the instructions will create. Since that model has proven to be durable, the steps to reproduce it can be recommended as a simple method for Scrapeboard players to construct a system of their own. Further improvements are covered by optional steps and more will likely be added in the future.
Supplies
--------
@ -48,15 +52,15 @@ Supplies
#### Hardware
* 4 × [plywood](https://www.homedepot.com/p/203504324) pre-cut to 15" × 21" × 3/4" each (oak or birch recommended)
* 4 × 12" × 18" metal sheets ([aluminum composite sheet](https://www.homedepot.com/p/308670310) cut into 4 pieces, [street signs](https://www.ebay.com/itm/134245723578), or if insetting with a router, [thin metal sheets](https://www.homedepot.com/p/204225782) are also an option)
* 4 × 12" × 18" metal sheets ([aluminum composite sheet](https://www.homedepot.com/p/308670310) cut into 4 pieces, [street signs](https://www.ebay.com/itm/134245723578), or if insetting with a router, thin metal sheets [pre-cut](https://www.lowes.com/pd/Hillman-12-in-x-18-in-Steel-Solid/3057631) or [cut your own](https://www.lowes.com/pd/IMPERIAL-24-in-x-3-ft-Galvanized-Steel-Sheet-Metal/3234805) are also an option)
* 52 × [Flat-head wood screws #8 × 5/8"](https://www.amazon.com/dp/B08F75F6BV)
* 4 × [#8 washers](https://www.homedepot.com/p/204276449)
* 8 × [Flat metal brackets with 5/8" screws](https://www.amazon.com/dp/B07Z8YLFCN)
* 20' [16 AWG wire](https://www.ebay.com/itm/272488348389)
* 20' - 30' [16 AWG wire](https://www.ebay.com/itm/272488348389)
* [Skateboard deck](https://www.ebay.com/sch?_nkw=blank+skateboard+deck)
* 2 × [Surface-mounted anchor rings](https://www.harborfreight.com/4-piece-surface-mounted-rope-rings-97767.html)
* 6 × [#10-24 × 3/4" machine screws](https://www.amazon.com/dp/B08474HKMT) with [hex nuts](https://www.amazon.com/dp/B082D6FV5H)
* 5 × [#8-1/2" Wood screws](https://www.amazon.com/dp/B09D952RV5)
* 10 × [#8-1/2" Wood screws](https://www.amazon.com/dp/B09D952RV5)
* [Thin metal strip](https://www.amazon.com/dp/B00745VXN2)
* [Non-slip floor padding](https://www.amazon.com/dp/B09QS47P21)
* [Carpet tape](https://www.amazon.com/dp/B07H88SWCM)
@ -65,10 +69,10 @@ Supplies
#### Tools
* Drill
* Hammer
* Straight edge
* Pencil
* Measuring tape
* Hot glue gun (recommended)
* Countersink bit (recommended)
* Wire strippers (recommended)
* Wrench (recommended)
@ -77,7 +81,7 @@ Supplies
#### Optional
* Use a [router](https://www.amazon.com/dp/B01M0J08MF) to create insets for the metal panels, inner screws, brackets, and wires
* Use a router to create insets for the metal panels, inner screws, brackets, and wires
* [3/4" straight bit](https://www.amazon.com/dp/B07ZC974L1)
* Replace 26 of the sheet metal screws with [#10-24 × 5/8" flat head machine screws](https://www.homedepot.com/p/310449137), [#10-24 nuts](https://www.homedepot.com/p/204274479), and [#10 1/2" washers](https://www.homedepot.com/p/204276450)
* Replace flat metal brackets with 8 [latches](https://www.amazon.com/dp/B07GKHD61X) and 32 [#4 × 1/4" round head screws](https://www.homedepot.com/p/204275185)
@ -92,7 +96,7 @@ Choosing the computer depends primarily on whether an Arduino or Raspberry Pi is
### Non-Raspberry Pi
Systems other than Raspberry Pi don't need special preparation before installing the software. They can work as is with an Arduino connected. The OS can be anything that runs Pygame, like a desktop computer or laptop running Windows, OS X, or Linux. It can be used like any ordinary computer by downloading the game software and attaching an Arduino, which will connect to the Scrapeboard pad.
Computers other than Raspberry Pi don't need special preparation before installing the software. They can work as is with an Arduino connected. The OS can be anything that runs Pygame, like a desktop computer or laptop running Windows, OS X, or Linux. The computer can be used like any ordinary computer by downloading the game software and attaching an Arduino, which will connect to the Scrapeboard pad.
### Raspberry Pi
@ -322,7 +326,7 @@ Four input pins on the microcontroller need to be connected to the game's four i
#### Arduino
1. Connect pins 2, 4, 6, and 11 to the breadboard using jumper wires
1. Connect pins 2, 3, 4, and 5 to the breadboard using jumper wires
2. Extend each connection using a 4.7k ohm resistor
3. End each connection with a screw terminal
@ -336,7 +340,7 @@ Four input pins on the microcontroller need to be connected to the game's four i
#### Arduino
Download the [Arduino IDE](https://www.arduino.cc/en/software) and connect it to the Arduino. Make sure the Arduino is connected in `Tools -> Port`. Open [serial/serial2/serial2.ino](serial/serial2/serial2.ino) in the IDE. Load the program into the Arduino using `Sketch -> Upload`.
Download the [Arduino IDE](https://www.arduino.cc/en/software) and connect it to the Arduino. Make sure the Arduino is connected in `Tools -> Port`. Open [serial/serial.ino](serial/serial.ino) in the IDE. Load the program into the Arduino using `Sketch -> Upload`.
#### Raspberry Pi
@ -391,7 +395,7 @@ The electronics are assumed to be installed in front of the platform, near where
* [Skateboard deck](https://www.ebay.com/sch?_nkw=blank+skateboard+deck)
* 2 × [Surface-mounted anchor rings](https://www.harborfreight.com/4-piece-surface-mounted-rope-rings-97767.html)
* 6 × [#10-24 × 3/4" machine screws](https://www.amazon.com/dp/B08474HKMT) with [hex nuts](https://www.amazon.com/dp/B082D6FV5H)
* 5 × [#8-1/2" Wood screws](https://www.amazon.com/dp/B09D952RV5)
* 10 × [#8-1/2" Wood screws](https://www.amazon.com/dp/B09D952RV5)
* [Thin metal strip](https://www.amazon.com/dp/B00745VXN2)
* [Non-slip floor padding](https://www.amazon.com/dp/B09QS47P21)
* [Carpet tape](https://www.amazon.com/dp/B07H88SWCM)
@ -404,7 +408,6 @@ The electronics are assumed to be installed in front of the platform, near where
* Straight edge
* Pencil
* Measuring tape
* Hot glue gun (recommended)
* Countersink bit (recommended)
* Wire strippers (recommended)
* Wrench (recommended)
@ -516,12 +519,12 @@ The platform is now finished. It can be connected to the Arduino or Raspberry Pi
The standard scrapeboard is a skatedeck with two round metal pads drilled into either end of the bottom. The pads are connected by a flat metal strip, creating a conductive contact across the length of the underside of the board. The recommended metal pads to use are actually anchor rings, ordinarily used to hook cargo to a tow cable. They are used because their unique disk shape and slightly raised edges allow for the best motion with the board. The board is subject to a lot of friction and pressure, so it's recommended to follow this manual unless intending to build a heavily modified version of the controller.
#### Wire strip
#### Metal strip
The wire strip is used to connect the metal pads to each other so the signal can pass through. The strip should be attached to the underside, going directly across the length of the middle. The metal pads will then be drilled on top of it.
The metal strip is used to connect the metal pads so the signal can be conducted from one to the other. The strip should be attached to the underside, going directly across the length of the middle. The metal pads will then be drilled on top of it.
1. Measure out and cut enough wire strip so that it will go along the entire flat part of the underside of the skatedeck. It doesn't have to go up the curved ends, but it should go past the truck holes.
2. Drill the wire strip directly into the underside of the board using the 1/2" wood screws.
2. Drill the wire strip directly into the underside of the board using the 1/2" wood screws, distributing the screws evenly and covering as much area along the length of the strip as possible.
#### Metal pads

View File

@ -11,7 +11,7 @@
#
# When run as a script, it prints connections detected between the input GPIO pins.
#
# Original algorithm by Dr. Clement Shimizu is translated from Arduino code in serial2.ino
# Original algorithm by Dr. Clement Shimizu is translated from Arduino code in serial/serial.ino
import time, itertools, argparse
import RPi.GPIO as GPIO

View File

@ -1,61 +0,0 @@
int pushButton1 = 2;
int pushButton2 = 4;
int pushButton3 = 6;
int pushButton4 = 11;
int buttons[4] = {pushButton1, pushButton2, pushButton3, pushButton4};
void setup() {
// set the digital pin as output:
Serial.begin(9600);
pinMode(pushButton1, OUTPUT);
digitalWrite(pushButton1, LOW);
pinMode(pushButton2, INPUT_PULLUP);
pinMode(pushButton3, INPUT_PULLUP);
pinMode(pushButton4, INPUT_PULLUP);
}
void loop() {
bool received_input = false;
for (int ii = 0; ii < 4; ii++)
{
for (int jj = 0; jj < 4; jj++)
{
if (jj == ii)
{
pinMode(buttons[jj], OUTPUT);
digitalWrite(buttons[jj], LOW);
}
else
{
pinMode(buttons[jj], INPUT_PULLUP);
}
}
for (int jj = ii; jj < 4; jj++)
{
if (!(ii == jj) && !digitalRead(buttons[jj]))
{
Serial.println(analogRead(buttons[jj]));
for (int kk = 3; kk >= 0; kk--)
{
if (kk == ii || kk == jj)
{
Serial.print(1);
}
else
{
Serial.print(0);
}
}
Serial.print("\n");
received_input = true;
break;
}
}
if (received_input)
{
break;
}
}
}

View File

@ -1,14 +1,25 @@
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// by Dr. Clement Shimizu for Scrapeboard
// constants won't change:
const long interval = 500; // interval at which to blink (milliseconds)
const long interval = 25; // 25 ms * 6 tests * 2 = 200 ms means 5 loops per second
/*
* Each pin corresponds with a panel on the platform and should be physically connected by a wire to the metal plate on the panel,
* with a 4.7k resistor in the connection.
*
* +--------------+--------------+
* | Arduino Pin | Panel Color |
* +-------------+--------------+--------------+
* | pushButton1 | Arduino PIN2 | Yellow Panel |
* | pushButton2 | Arduino PIN3 | Pink Panel |
* | pushButton3 | Arduino PIN4 | Blue Panel |
* | pushButton4 | Arduino PIN5 | Red Panel |
* +-------------+--------------+--------------+
*/
int pushButton1 = 2;
int pushButton2 = 4;
int pushButton3 = 6;
int pushButton4 = 11;
int pushButton2 = 3;
int pushButton3 = 4;
int pushButton4 = 5;
int buttons[4] = {
pushButton1,
@ -33,12 +44,11 @@ bool testConnection2(int A, int B) {
pinMode(buttons[i], OUTPUT);
digitalWrite(buttons[i], LOW);
} else {
// digitalWrite(buttons[i], HIGH);
pinMode(buttons[i], INPUT_PULLUP);
}
}
// delay(10);
delay(interval);
if (!digitalRead(buttons[B])) {
return true;
} else {
@ -49,89 +59,19 @@ bool testConnection(int A, int B) {
return testConnection2(A, B) && testConnection2(B, A);
}
// int lastNumber = -1;
void loop() {
if (testConnection(0, 1)) {
// if (lastNumber != 01) {
// lastNumber = 01;
Serial.println("0011");
// }
Serial.println("0011");
} else if (testConnection(0, 2)) {
// if (lastNumber != 02) {
// lastNumber = 02;
Serial.println("0101");
// }
Serial.println("0101");
} else if (testConnection(0, 3)) {
// if (lastNumber != 03) {
// lastNumber = 03;
Serial.println("1001");
// }
Serial.println("1001");
} else if (testConnection(1, 2)) {
// if (lastNumber != 12) {
// lastNumber = 12;
Serial.println("0110");
// }
Serial.println("0110");
} else if (testConnection(1, 3)) {
// if (lastNumber != 13) {
// lastNumber = 13;
Serial.println("1010");
// }
Serial.println("1010");
} else if (testConnection(2, 3)) {
// if (lastNumber != 23) {
// lastNumber = 23;
Serial.println("1100");
// }
// } else {
// if (lastNumber != 0) {
// lastNumber = 0;
// Serial.println("0000");
// }
Serial.println("1100");
}
}
/*
for (int ii = 0; ii < 4; ii++)
{
for (int jj = 0; jj < 4; jj++)
{
if (jj == ii)
{
pinMode(buttons[jj], OUTPUT);
digitalWrite(buttons[jj], LOW);
}
else
{
pinMode(buttons[jj], INPUT_PULLUP);
}
}
for (int jj = ii; jj < 4; jj++)
{
if (!(ii == jj) && !digitalRead(buttons[jj]))
{
for (int kk = 3; kk >= 0; kk--)
{
if (kk == ii || kk == jj)
{
Serial.print(1);
}
else
{
Serial.print(0);
}
}
Serial.print("\n");
received_input = true;
break;
}
}
// if (received_input)
// {
// break;
// }
}
*/

View File

@ -1,137 +0,0 @@
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change:
const long interval = 500; // interval at which to blink (milliseconds)
int pushButton1 = 2;
int pushButton2 = 4;
int pushButton3 = 6;
int pushButton4 = 11;
int buttons[4] = {
pushButton1,
pushButton2,
pushButton3,
pushButton4
};
void setup() {
// set the digital pin as output:
Serial.begin(9600);
pinMode(pushButton1, OUTPUT);
digitalWrite(pushButton1, LOW);
pinMode(pushButton2, INPUT_PULLUP);
pinMode(pushButton3, INPUT_PULLUP);
pinMode(pushButton4, INPUT_PULLUP);
}
bool testConnection2(int A, int B) {
for (int i = 0; i < 4; i++) {
if (i == A) {
pinMode(buttons[i], OUTPUT);
digitalWrite(buttons[i], LOW);
} else {
// digitalWrite(buttons[i], HIGH);
pinMode(buttons[i], INPUT_PULLUP);
}
}
// delay(10);
if (!digitalRead(buttons[B])) {
return true;
} else {
return false;
}
}
bool testConnection(int A, int B) {
return testConnection2(A, B) && testConnection2(B, A);
}
// int lastNumber = -1;
void loop() {
if (testConnection(0, 1)) {
// if (lastNumber != 01) {
// lastNumber = 01;
Serial.println("0011");
// }
} else if (testConnection(0, 2)) {
// if (lastNumber != 02) {
// lastNumber = 02;
Serial.println("0101");
// }
} else if (testConnection(0, 3)) {
// if (lastNumber != 03) {
// lastNumber = 03;
Serial.println("1001");
// }
} else if (testConnection(1, 2)) {
// if (lastNumber != 12) {
// lastNumber = 12;
Serial.println("0110");
// }
} else if (testConnection(1, 3)) {
// if (lastNumber != 13) {
// lastNumber = 13;
Serial.println("1010");
// }
} else if (testConnection(2, 3)) {
// if (lastNumber != 23) {
// lastNumber = 23;
Serial.println("1100");
// }
// } else {
// if (lastNumber != 0) {
// lastNumber = 0;
// Serial.println("0000");
// }
}
}
/*
for (int ii = 0; ii < 4; ii++)
{
for (int jj = 0; jj < 4; jj++)
{
if (jj == ii)
{
pinMode(buttons[jj], OUTPUT);
digitalWrite(buttons[jj], LOW);
}
else
{
pinMode(buttons[jj], INPUT_PULLUP);
}
}
for (int jj = ii; jj < 4; jj++)
{
if (!(ii == jj) && !digitalRead(buttons[jj]))
{
for (int kk = 3; kk >= 0; kk--)
{
if (kk == ii || kk == jj)
{
Serial.print(1);
}
else
{
Serial.print(0);
}
}
Serial.print("\n");
received_input = true;
break;
}
}
// if (received_input)
// {
// break;
// }
}
*/

View File

@ -1,64 +0,0 @@
// by Dr. Clement Shimizu for Scrapeboard
// constants won't change:
const long interval = 25; // 25 ms * 6 tests * 2 = 200 ms means 5 loops per second
int pushButton1 = 2;
int pushButton2 = 4;
int pushButton3 = 6;
int pushButton4 = 11;
int buttons[4] = {
pushButton1,
pushButton2,
pushButton3,
pushButton4
};
void setup() {
// set the digital pin as output:
Serial.begin(9600);
pinMode(pushButton1, OUTPUT);
digitalWrite(pushButton1, LOW);
pinMode(pushButton2, INPUT_PULLUP);
pinMode(pushButton3, INPUT_PULLUP);
pinMode(pushButton4, INPUT_PULLUP);
}
bool testConnection2(int A, int B) {
for (int i = 0; i < 4; i++) {
if (i == A) {
pinMode(buttons[i], OUTPUT);
digitalWrite(buttons[i], LOW);
} else {
pinMode(buttons[i], INPUT_PULLUP);
}
}
delay(interval);
if (!digitalRead(buttons[B])) {
return true;
} else {
return false;
}
}
bool testConnection(int A, int B) {
return testConnection2(A, B) && testConnection2(B, A);
}
void loop() {
if (testConnection(0, 1)) {
Serial.println("0011");
} else if (testConnection(0, 2)) {
Serial.println("0101");
} else if (testConnection(0, 3)) {
Serial.println("1001");
} else if (testConnection(1, 2)) {
Serial.println("0110");
} else if (testConnection(1, 3)) {
Serial.println("1010");
} else if (testConnection(2, 3)) {
Serial.println("1100");
}
}