Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions arduino/PAPR_controller/PAPR_controller.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <Servo.h>

#define SERV1 3
#define MIN_SERVO 0
#define MAX_SERVO 180
#define STEP_SERVO 18

#define DEC_BUTTON 4
#define INC_BUTTON 12
#define DEBOUNCE_MS 100

Servo control;
void setup() {
control.attach(SERV1);

pinMode(INC_BUTTON,INPUT_PULLUP);
pinMode(DEC_BUTTON,INPUT_PULLUP);
Serial.begin(115200);
Serial.println("PAPR Controller (WyoLum.com)");
}

int setting = MIN_SERVO;
void inc(){
setting += STEP_SERVO;
if(setting > MAX_SERVO) setting = MAX_SERVO;
}
void dec(){
setting -= STEP_SERVO;
if(setting < MIN_SERVO) setting=MIN_SERVO;
}

unsigned long last_press = 0;
void interact(){
if(millis() - last_press > DEBOUNCE_MS){
if(digitalRead(INC_BUTTON) == LOW){
inc();
Serial.println("inc");
Serial.print(setting);
while(digitalRead(INC_BUTTON) == LOW){
// wait for release
}
last_press = millis();
}
if(digitalRead(DEC_BUTTON) == LOW){
dec();
Serial.println("dec");
Serial.print(setting);
while(digitalRead(DEC_BUTTON) == LOW){
// wait for release
}
last_press = millis();
}
}
}
void loop(){
interact();
control.write(setting);
}
File renamed without changes.
File renamed without changes.
143 changes: 143 additions & 0 deletions arduino/RAF3/RAF3.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include <FastLED.h>

#include <Servo.h>

#define SOLENOID 2
#define PUMP 9
#define BUTTON 12
#define JOYX A0
#define JOYY A1
#define SERV1 3
#define SERV2 5
#define SERV3 6
#define LIGHT A2
#define TEMP A3
#define NEOPIXELPIN 8
#define NUM_LEDS 1
CRGB leds[NUM_LEDS];
#define DATA_PIN NEOPIXELPIN
#define BRIGHTNESS 20
const int MAX_AZ = 180;
const int MIN_AZ = 0;
const int MAX_EL = 125;
const int MIN_EL = 0;
const float AZ_GAIN = 1./8000.;
const float EL_GAIN = 1./4000.;
Servo azimuth;
Servo elevation;

int xCenter, yCenter;

void setup() {
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);

Serial.begin(115200);
Serial.println("Ready Aim Fire!");


azimuth.attach(SERV1);
elevation.attach(SERV2);
azimuth.write(80);
elevation.write(3);
pinMode(SOLENOID,OUTPUT);
digitalWrite(SOLENOID,LOW);
pinMode(PUMP,OUTPUT);
digitalWrite(PUMP, LOW);
pinMode(BUTTON,INPUT_PULLUP);
leds[0] = CRGB::Black;
FastLED.show();
xCenter = analogRead(JOYX);
yCenter = analogRead(JOYY);
digitalWrite(PUMP,HIGH);
delay(100);
leds[0] = CRGB::Red;
FastLED.show();
delay(200);
leds[0] = CRGB::Green;
FastLED.show();
delay(200);
leds[0] = CRGB::Blue;
FastLED.show();
delay(200);

}
void chase()
{
// Move a single white led
for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
// Turn our current led on to white, then show the leds
leds[whiteLed] = CRGB::White;

// Show the leds (only one of which is set to white, from above)
FastLED.show();

// Wait a little bit
delay(250);

// Turn our current led back to black for the next loop around
leds[whiteLed] = CRGB::Black;
FastLED.show();
}
}
int lastx;
int lasty;
float current_az = 90;
float current_el = 45;

void loop() {
int xReading,yReading;
int light = analogRead(LIGHT);
int temp = analogRead(TEMP);
if (digitalRead(BUTTON) == LOW){
Serial.println("fire!");
digitalWrite(SOLENOID,HIGH);
delay(250);
digitalWrite(SOLENOID,LOW);
chase();
digitalWrite(PUMP,HIGH);
delay(3000);
digitalWrite(PUMP, LOW);
delay(100);
}
xReading = analogRead(JOYX);
yReading = analogRead(JOYY);

/*
Serial.print("xReading: ");
Serial.print(xReading);
Serial.print(", yReading: ");
Serial.print(yReading);

Serial.print(", delta_az: ");
Serial.print(delta_az);
Serial.print(", current_az: ");
Serial.print(current_az);

Serial.print(", delta_el: ");
Serial.print(delta_el);
Serial.print(", current_el: ");
Serial.println(current_el);
*/

float delta_az = - AZ_GAIN * (xReading - xCenter);
current_az += delta_az;
if(current_az > MAX_AZ){
current_az = MAX_AZ;
}
if(current_az < MIN_AZ){
current_az = MIN_AZ;
}
float delta_el = EL_GAIN * (yReading - yCenter);
current_el += delta_el;
if(current_el > MAX_EL){
current_el = MAX_EL;
}
if(current_el < MIN_EL){
current_el = MIN_EL;
}
azimuth.write(current_az);
elevation.write(current_el);
return;

}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#define LIGHT A2
#define TEMP A3
#define NEOPIXELPIN 8
#define NUM_LEDS 1
CRGB leds[NUM_LEDS];

Servo azimuth;
Servo elevation;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.