Commit 6cdb7c34 authored by Werner Sembach's avatar Werner Sembach
Browse files

new riddle

parent 27ea4474
......@@ -3,10 +3,11 @@
#include "Util.h"
#include "easy_riddle.h"
//#include "easy_riddle.h"
//#include "hill_riddle.h"
//#include "lever_riddle.h"
//#include "nine_riddle.h"
#include "presentation_riddle.h"
//#include "spring_riddle.h"
#define STACKSIZE (CYGNUM_HAL_STACK_SIZE_MINIMUM+1024)
......
#pragma once
#include <stdio.h>
#include "DCMotor.h"
#include "ExternButton.h"
#include "LeverKey.h"
#include "ServoMotor.h"
#include "Util.h"
void riddle(void) {
bool button_pressed = false;
bool spring_broken = false;
bool levers_set = false;
servo_set_percent(SERVO_0, 0.5);
dc_set_percent(0, 0.0);
/*About the spring struct:
unsigned int threshold: remember the potty protection zones
uint8_t direction: SPRING_LEFT, SPRING_LEFT direction the spring is turning in this interval
double power: between 0 and 1.0; power < 0 makes it linear to the adc value
bool solved: the bool that is returned if the adc value is below the threshold (set it to true in the range the riddle should be solved)
-> the structs have have to be sorted ascending by threshold*/
bool springa_broken = false;
bool springb_broken = false;
bool unlocked_b = false;
//'balancing on the mountain' -> botm
Spring riddle2a[7];
set_spring(&riddle2a[0], 512, SPRING_NOTHING, 0.0, false);
set_spring(&riddle2a[1], 1000, 0, 0.0, false);
set_spring(&riddle2a[2], 1900, SPRING_RIGHT, 0.5, false);
set_spring(&riddle2a[3], 2100, 0, 0.0, true); //solved
set_spring(&riddle2a[4], 3000, SPRING_LEFT, 0.5, false);
set_spring(&riddle2a[5], 4096 - 512, 0, 0.0, false);
set_spring(&riddle2a[6], 4096, SPRING_NOTHING, 0.0, false);
//'climb out of the valley' -> cootv
Spring riddle2b[7];
set_spring(&riddle2b[0], 512, SPRING_NOTHING, 0.0, false);
set_spring(&riddle2b[1], 1000, 0, 0.0, true); //solved
set_spring(&riddle2b[2], 1900, SPRING_LEFT, 0.5, false);
set_spring(&riddle2b[3], 2100, 0, 0.0, false);
set_spring(&riddle2b[4], 3000, SPRING_RIGHT, 0.5, false);
set_spring(&riddle2b[5], 4096 - 512, 0, 0.0, true); //solved
set_spring(&riddle2b[6], 4096, SPRING_NOTHING, 0.0, false);
while(true) {
//poti protection
bool protection = block_spring(LOWER_BOUND, 256) || block_spring(UPPER_BOUND, 4096 - 256);
//check if solved
if(spring_broken && levers_set) {
printf("CONGRATULATIONS! YOU FINALLY MADE IT!\n");
servo_set_percent(SERVO_0, 1.0);
dc_set_percent(0, 0.0);
break;
}
button_pressed = button_get();
//button has to be pressed when 'botm' is solved
if (!unlocked_b) {
springa_broken = simulate_spring(riddle2a, 7);
}
if (springa_broken && !unlocked_b) {
if(button_pressed){
unlocked_b = true;
}
}
//if the button is pressed when the 'cootv' riddle is solved, you have to solve the 'botm' riddle again
if (unlocked_b) {
springb_broken = simulate_spring(riddle2b, 7);
}
if (springb_broken) {
if (button_pressed) {
unlocked_b = false;
springa_broken = false;
springb_broken = false;
}
}
if (springa_broken && springb_broken) {
dc_set_percent(0, 0.0);
spring_broken = true;
}
levers_set = lever_get(LEVER_0) == 1 && lever_get(LEVER_3) == 1 && lever_get(LEVER_1) == -1 && lever_get(LEVER_2) == -1;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment