Add spectroscopy amplifier (model 2020)

This commit is contained in:
redfast00 2022-02-11 21:13:52 +01:00
parent 91f6c4bab4
commit 9b52e74743
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
3 changed files with 102 additions and 0 deletions

View file

@ -189,6 +189,12 @@ pre {
<td class="mod-nm">Doolhof</td>
<td class="remark"></td>
</tr>
<tr id="puzzle-1">
<td class="mod-id">1</td>
<td class="issuee">Zeus WPI</td>
<td class="mod-nm">Spectroscopy Amplifier (model 2020)</td>
<td class="remark"></td>
</tr>
<tr id="puzzle-255">
<td class="mod-id">255</td>
<td class="issuee"><span class="keyword">private use</span></td>

View file

@ -0,0 +1,20 @@
# Spectroscopy Amplifier (model 2020)
Schrijf de handleiding voor je module hier. Kijk gerust naar de handleiding
voor de "Doolhof"-module (`src/modules/puzzle_maze/doc/index.md`)
Hieronder wat voorbeelden van markup die je kan gebruiken. Daarnaast kan je ook LaTeX
gebruiken (zie bijvoorbeeld de "Doolhof"-module)
Use drawings! Create the docs/images/your_module directory, put your image there and include them like this:
![](./your_module/filename.png)
Use tables! Write them like this:
| Symbol | Action to take |
|--------------------------------|----------------|
| ![](./your_module/symbol1.png) | Do nothing |
| ![](./your_module/symbol2.png) | Press the red button |
| ![](./your_module/symbol3.png) | Press the yellow button |

View file

@ -0,0 +1,76 @@
// (c) 2022, redfast00
// See the LICENSE file for conditions for copying
#include <obus_module.h>
// The shaping multiplier button has a bad contact when held down: wiggling the button will break/make contact
// #define SHAPING_MULTIPLIER_PIN 10
#define INPUT_POLARITY_PIN A2
#define RESTORER_RATE_PIN A3
#define RESTORER_MODE_PIN A4
#define THRESHOLD_PIN A5
#define PUR_PIN 9
#define VAR_LED 5
#define DISC_LED 6
#define COARSE_GAIN_NETWORK_PIN A0
#define SHAPING_TIME_NETWORK_PIN A1
// Gets the position of a dial, given the pin connected to the resistor network
uint8_t get_resistor_network_pin_index(uint8_t pin) {
int expected_values[6] = {0, 254, 407, 509, 582, 638};
int measured = analogRead(pin);
int minimal_difference = 1024;
uint8_t best_candidate = 0;
for (uint8_t i = 0; i < 6; i++) {
int difference = abs(measured - expected_values[i]);
if (difference < minimal_difference) {
minimal_difference = difference;
best_candidate = i;
}
}
return best_candidate;
}
void setup() {
Serial.begin(115200);
obus_module::setup(OBUS_TYPE_PUZZLE, 1);
// Switches and buttons
pinMode(INPUT_POLARITY_PIN, INPUT_PULLUP);
pinMode(RESTORER_RATE_PIN, INPUT_PULLUP);
pinMode(RESTORER_MODE_PIN, INPUT_PULLUP);
pinMode(THRESHOLD_PIN, INPUT_PULLUP);
pinMode(PUR_PIN, INPUT_PULLUP);
// LEDs
pinMode(VAR_LED, OUTPUT);
pinMode(DISC_LED, OUTPUT);
// resistor networks
pinMode(COARSE_GAIN_NETWORK_PIN, INPUT);
pinMode(SHAPING_TIME_NETWORK_PIN, INPUT);
}
obus_can::message message;
void loop() {
obus_module::loopPuzzle(&message, callback_game_start, callback_game_stop);
// Some demo code to show everything works
bool var_value = digitalRead(INPUT_POLARITY_PIN) ^ digitalRead(RESTORER_MODE_PIN) ^ digitalRead(RESTORER_RATE_PIN) ^ digitalRead(THRESHOLD_PIN);
bool disc_value = (get_resistor_network_pin_index(COARSE_GAIN_NETWORK_PIN) % 2) ^ (get_resistor_network_pin_index(SHAPING_TIME_NETWORK_PIN) % 2) ^ digitalRead(PUR_PIN);
digitalWrite(VAR_LED, var_value);
digitalWrite(DISC_LED, disc_value);
}
void callback_game_start() {
// just instantly solve
obus_module::solve();
}
void callback_game_stop() {
}