Skip to content

Commit a2f3a50

Browse files
committed
emergency backup
1 parent c52ec39 commit a2f3a50

File tree

5 files changed

+305
-16
lines changed

5 files changed

+305
-16
lines changed

Onirisation.new/Onirisation.new.ino

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#include <Servo.h>
2+
3+
/*
4+
* modify the folowing variables to fit the number of fans, servos, sensors
5+
*/
6+
7+
const int panelPin = 3; // led panel pin
8+
const int servoPins[] = {5, 6, 7}; // non PWM pins for servos
9+
const int fsrAnalogPin[] = {0}; // FSR analog pins
10+
const int ventilPin[] = {11, 12, 13}; // PWM pins for ventilos
11+
const int lowTresh = 30; // set lowest limit for driving ventilos
12+
const int highTresh = 170; // set highest limit for driving ventilos
13+
const unsigned long lagTime = 1000; // set lag time for driving each ventilos
14+
const int noDialPin = 9;
15+
const int countPin = 10;
16+
17+
/* ventilVal
18+
* deffault parameters
19+
*/
20+
21+
const int servoNum = sizeof(servoPins) / sizeof(servoPins[0]); // number of servos
22+
const int fsrNum = sizeof(fsrAnalogPin) / sizeof(fsrAnalogPin[0]); // number of resistive sensors
23+
const int ventilNum = sizeof(ventilPin) / sizeof(ventilPin[0]); // number of ventilos
24+
25+
Servo myServos[servoNum]; // create servo objects
26+
int fsrReading[fsrNum]; // value sent to score
27+
int ventilVal[ventilNum]; // value received from score
28+
int servoVal[servoNum];
29+
int previousVal[ventilNum]; // keep track of previous vlaues
30+
unsigned long timeElapsed; // keep track of time past
31+
unsigned long lastTime[ventilNum]; // store date for mesuring durations
32+
int count = 0;
33+
int prevState = 0;
34+
35+
void setup() {
36+
37+
Serial.begin(9600); // set baud rate
38+
39+
for (int i = 0; i < ventilNum; i++) {
40+
pinMode(ventilPin[i], OUTPUT); // define pin as output
41+
previousVal[i] = 0; // initialise all previousVal to 0
42+
lastTime[i] = 0; // initialise all lastTimes to 0
43+
ventilVal[i] = 0; // initialise all ventilVal to 0
44+
}
45+
46+
for (int i = 0; i < servoNum; i++) {
47+
myServos[i].attach(servoPins[i], 800, 2200); // define servo range
48+
myServos[i].writeMicroseconds(1500); // servo initial value
49+
}
50+
51+
pinMode(panelPin, OUTPUT); // define pin as output
52+
pinMode(noDialPin, INPUT_PULLUP); // define pin as inpout
53+
pinMode(countPin, INPUT_PULLUP); // define pin as inpout
54+
55+
}
56+
57+
void loop() {
58+
59+
timeElapsed = millis(); // update current date
60+
/*
61+
for (int i = 0; i < fsrNum; i++) {
62+
fsrReading[i] = analogRead(fsrAnalogPin[i]);
63+
Serial.print(fsrReading[i]); // read anog pin and send it through serial
64+
if (i == (fsrNum - 1)) {
65+
Serial.println();
66+
} else {
67+
Serial.print(',');
68+
}
69+
}
70+
*/
71+
72+
if(!digitalRead(noDialPin)) {
73+
int curentState = digitalRead(countPin);
74+
if((curentState == 0) && (prevState == 1)) {
75+
count++;
76+
}
77+
prevState = curentState;
78+
} else {
79+
if(count != 0) {
80+
Serial.println(count - 1);
81+
count = 0;
82+
}
83+
}
84+
85+
// Serial.print(digitalRead(dialPin)) ;
86+
87+
while (Serial.available() > 0) {
88+
switch (Serial.read()) { // switch for the folowing characters
89+
case 'p':
90+
analogWrite(panelPin, Serial.parseInt());
91+
break;
92+
case 'l':
93+
servoVal[0] = map(Serial.parseInt(), 0, 90, 800, 2200) ;
94+
Serial.print(servoVal[0]);
95+
myServos[0].writeMicroseconds(servoVal[0]);
96+
break;
97+
case 'c':
98+
servoVal[1] = map(Serial.parseInt(), 0, 90, 800, 2200) ;
99+
Serial.print(servoVal[1]);
100+
myServos[1].writeMicroseconds(servoVal[1]);
101+
break;
102+
case 'r':
103+
servoVal[2] = map(Serial.parseInt(), 0, 90, 800, 2200) ;
104+
Serial.print(servoVal[2]);
105+
myServos[2].writeMicroseconds(servoVal[2]);
106+
break;
107+
case 'v':
108+
Serial.print('v');
109+
ventilVal[0] = Serial.parseInt();
110+
break;
111+
case 'w':
112+
Serial.print('w');
113+
ventilVal[1] = Serial.parseInt();
114+
break;
115+
case 'x':
116+
Serial.print('x');
117+
ventilVal[2] = Serial.parseInt();
118+
break;
119+
}
120+
}
121+
122+
for (int i = 0; i < ventilNum; i++) {
123+
if ((timeElapsed - lastTime[i]) >= lagTime) {
124+
if (needStarter(ventilVal[i], previousVal[i])) {
125+
digitalWrite(ventilPin[i], HIGH);
126+
lastTime[i] = timeElapsed;
127+
} else {
128+
digitalWrite(ventilPin[i], ventilVal[i]);
129+
}
130+
}
131+
}
132+
133+
Serial.flush();
134+
delay(1);
135+
}
136+
137+
bool needStarter(int val, int &prev) {
138+
139+
if ((val >= lowTresh) && (val < highTresh)) {
140+
if (prev < highTresh) {
141+
prev = 255;
142+
return true;
143+
} else {
144+
return false;
145+
}
146+
} else {
147+
prev = val;
148+
return false;
149+
}
150+
}

Onirisation/Onirisation.ino

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#include <Servo.h>
2+
3+
/*
4+
* modify the folowing variables to fit the number of fans, servos, sensors
5+
*/
6+
7+
const int panelPin = 11; // led panel pin
8+
const int servoPins[] = {2, 4, 7}; // non PWM pins for servos
9+
const int fsrAnalogPin[] = {0}; // FSR analog pins
10+
const int ventilPin[] = {3, 5, 6}; // PWM pins for ventilos
11+
const int lowTresh = 30; // set lowest limit for driving ventilos
12+
const int highTresh = 170; // set highest limit for driving ventilos
13+
const unsigned long lagTime = 1000; // set lag time for driving each ventilos
14+
const int noDialPin = 9;
15+
const int countPin = 10;
16+
17+
/* ventilVal
18+
* deffault parameters
19+
*/
20+
21+
const int servoNum = sizeof(servoPins) / sizeof(servoPins[0]); // number of servos
22+
const int fsrNum = sizeof(fsrAnalogPin) / sizeof(fsrAnalogPin[0]); // number of resistive sensors
23+
const int ventilNum = sizeof(ventilPin) / sizeof(ventilPin[0]); // number of ventilos
24+
25+
Servo myServos[servoNum]; // create servo objects
26+
int fsrReading[fsrNum]; // value sent to score
27+
int ventilVal[ventilNum]; // value received from score
28+
int previousVal[ventilNum]; // keep track of previous vlaues
29+
unsigned long timeElapsed; // keep track of time past
30+
unsigned long lastTime[ventilNum]; // store date for mesuring durations
31+
int count = 0;
32+
int prevState = 0;
33+
34+
void setup() {
35+
36+
Serial.begin(9600); // set baud rate
37+
38+
for (int i = 0; i < ventilNum; i++) {
39+
pinMode(ventilPin[i], OUTPUT); // define pin as output
40+
previousVal[i] = 0; // initialise all previousVal to 0
41+
lastTime[i] = 0; // initialise all lastTimes to 0
42+
ventilVal[i] = 0; // initialise all ventilVal to 0
43+
}
44+
45+
for (int i = 0; i < servoNum; i++) {
46+
myServos[i].attach(servoPins[i], 800, 2200); // define servo range
47+
myServos[i].writeMicroseconds(1500); // servo initial value
48+
}
49+
50+
pinMode(panelPin, OUTPUT); // define pin as output
51+
pinMode(noDialPin, INPUT_PULLUP); // define pin as inpout
52+
pinMode(countPin, INPUT_PULLUP); // define pin as inpout
53+
54+
}
55+
56+
void loop() {
57+
58+
timeElapsed = millis(); // update current date
59+
/*
60+
for (int i = 0; i < fsrNum; i++) {
61+
fsrReading[i] = analogRead(fsrAnalogPin[i]);
62+
Serial.print(fsrReading[i]); // read anog pin and send it through serial
63+
if (i == (fsrNum - 1)) {
64+
Serial.println();
65+
} else {
66+
Serial.print(',');
67+
}
68+
}
69+
*/
70+
71+
if(!digitalRead(noDialPin)) {
72+
int curentState = digitalRead(countPin);
73+
if((curentState == 0) && (prevState == 1)) {
74+
count++;
75+
}
76+
prevState = curentState;
77+
} else {
78+
if(count != 0) {
79+
Serial.println(count - 1);
80+
count = 0;
81+
}
82+
}
83+
84+
// Serial.print(digitalRead(dialPin)) ;
85+
86+
while (Serial.available() > 0) {
87+
switch (Serial.read()) { // switch for the folowing characters
88+
case 'p':
89+
analogWrite(panelPin, Serial.parseInt());
90+
break;
91+
case 'l':
92+
myServos[0].writeMicroseconds(
93+
map(Serial.parseInt(), 0, 90, 800, 2200)
94+
);
95+
break;
96+
case 'c':
97+
myServos[1].writeMicroseconds(
98+
map(Serial.parseInt(), 0, 90, 800, 2200)
99+
);
100+
break;
101+
case 'r':
102+
myServos[2].writeMicroseconds(
103+
map(Serial.parseInt(), 0, 90, 800, 2200)
104+
);
105+
break;
106+
case 'v':
107+
ventilVal[0] = Serial.parseInt();
108+
break;
109+
case 'w':
110+
ventilVal[1] = Serial.parseInt();
111+
break;
112+
case 'x':
113+
ventilVal[2] = Serial.parseInt();
114+
break;
115+
}
116+
}
117+
118+
for (int i = 0; i < ventilNum; i++) {
119+
if ((timeElapsed - lastTime[i]) >= lagTime) {
120+
if (needStarter(ventilVal[i], previousVal[i])) {
121+
analogWrite(ventilPin[i], 255);
122+
lastTime[i] = timeElapsed;
123+
} else {
124+
analogWrite(ventilPin[i], ventilVal[i]);
125+
}
126+
}
127+
}
128+
129+
Serial.flush();
130+
delay(1);
131+
}
132+
133+
bool needStarter(int val, int &prev) {
134+
135+
if ((val >= lowTresh) && (val < highTresh)) {
136+
if (prev < highTresh) {
137+
prev = 255;
138+
return true;
139+
} else {
140+
return false;
141+
}
142+
} else {
143+
prev = val;
144+
return false;
145+
}
146+
}

Onirisation/oni.device

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Device":{"Name":"onirisation","Protocol":"50c48ef3-8e60-400e-9a51-2ab535ad87eb","Port":"6493832333135111A072","Text":"/*\n * This example comunicates with the arduino sketch of the same name\n * you can find this corresponding example sketch on the arduino website\n * visit: https://www.arduino.cc/en/Tutorial/BuiltInExamples\n * These examples are included in the Arduino IDE\n * as well as in the Web Editor under Examples/BUILT IN\n * for any issue on the ossia-score side, please report to:\n * https://github.com/OSSIA/score-user-library/issues\n */\n\nimport Score 1.0\nimport Ossia 1.0 as Ossia\n\nOssia.Serial\n{\n function openListening(address) {}\n function closeListening(address) {}\n\n function onMessage(message) { // evaluated each time a message is received\n\n\t//console.log(message);\n\n return [{ address: \"/FSR\", value: parseInt(message) }];\n }\n\n function createTree() {\n return [\n {\n name: \"FSR\",\n type: Ossia.Type.Int,\n min: 0,\n max: 1023,\n access: Ossia.Access.Get,\n bounding: Ossia.Bounding.Clip,\n repetition_filter: Ossia.Repetitions.Filtered\n },\n {\n name: \"PanelLed\",\n type: Ossia.Type.Int,\n min: 0,\n max: 255,\n access: Ossia.Access.Set,\n bounding: Ossia.Bounding.Clip,\n request: \"p$val\",\n repetition_filter: Ossia.Repetitions.Filtered\n },\n {\n name: \"ServoL\",\n type: Ossia.Type.Int,\n min: 0,\n max: 150,\n access: Ossia.Access.Set,\n bounding: Ossia.Bounding.Clip,\n request: \"l$val\",\n repetition_filter: Ossia.Repetitions.Filtered\n },\n {\n name: \"ServoC\",\n type: Ossia.Type.Int,\n min: 0,\n max: 150,\n access: Ossia.Access.Set,\n bounding: Ossia.Bounding.Clip,\n request: \"c$val\",\n repetition_filter: Ossia.Repetitions.Filtered\n },\n {\n name: \"ServoR\",\n type: Ossia.Type.Int,\n min: 0,\n max: 150,\n access: Ossia.Access.Set,\n bounding: Ossia.Bounding.Clip,\n request: \"r$val\",\n repetition_filter: Ossia.Repetitions.Filtered\n },\n {\n name: \"VentiloV\",\n type: Ossia.Type.Int,\n min: 0,\n max: 255,\n access: Ossia.Access.Set,\n bounding: Ossia.Bounding.Clip,\n request: \"v$val\",\n repetition_filter: Ossia.Repetitions.Filtered\n },\n {\n name: \"VentiloW\",\n type: Ossia.Type.Int,\n min: 0,\n max: 255,\n access: Ossia.Access.Set,\n bounding: Ossia.Bounding.Clip,\n request: \"w$val\",\n repetition_filter: Ossia.Repetitions.Filtered\n },\n {\n name: \"VentiloX\",\n type: Ossia.Type.Int,\n min: 0,\n max: 255,\n access: Ossia.Access.Set,\n bounding: Ossia.Bounding.Clip,\n request: \"x$val\",\n repetition_filter: Ossia.Repetitions.Filtered\n }\n ];\n }\n}\n","Rate":9600},"Children":[{"Address":{"ioType":"<->","ClipMode":"Clip","RepetitionFilter":true,"Value":{"Int":0},"Domain":{},"Name":"FSR"}},{"Address":{"ioType":"<->","ClipMode":"Clip","RepetitionFilter":true,"Value":{"Int":0},"Domain":{},"Name":"PanelLed"}},{"Address":{"ioType":"<->","ClipMode":"Clip","RepetitionFilter":true,"Value":{"Int":45},"Domain":{},"Name":"ServoL"}},{"Address":{"ioType":"<->","ClipMode":"Clip","RepetitionFilter":true,"Value":{"Int":0},"Domain":{},"Name":"ServoC"}},{"Address":{"ioType":"<->","ClipMode":"Clip","RepetitionFilter":true,"Value":{"Int":0},"Domain":{},"Name":"ServoR"}},{"Address":{"ioType":"<->","ClipMode":"Clip","RepetitionFilter":true,"Value":{"Int":0},"Domain":{},"Name":"VentiloV"}},{"Address":{"ioType":"<->","ClipMode":"Clip","RepetitionFilter":true,"Value":{"Int":0},"Domain":{},"Name":"VentiloW"}},{"Address":{"ioType":"<->","ClipMode":"Clip","RepetitionFilter":true,"Value":{"Int":0},"Domain":{},"Name":"VentiloX"}}]}

onirisation.qml

+7-16
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* https://github.com/OSSIA/score-user-library/issues
99
*/
1010

11-
import QtQuick 2.0
11+
import Score 1.0
1212
import Ossia 1.0 as Ossia
1313

1414
Ossia.Serial
@@ -48,7 +48,7 @@ Ossia.Serial
4848
name: "ServoL",
4949
type: Ossia.Type.Int,
5050
min: 0,
51-
max: 150,
51+
max: 90,
5252
access: Ossia.Access.Set,
5353
bounding: Ossia.Bounding.Clip,
5454
request: "l$val",
@@ -58,7 +58,7 @@ Ossia.Serial
5858
name: "ServoC",
5959
type: Ossia.Type.Int,
6060
min: 0,
61-
max: 150,
61+
max: 90,
6262
access: Ossia.Access.Set,
6363
bounding: Ossia.Bounding.Clip,
6464
request: "c$val",
@@ -68,39 +68,30 @@ Ossia.Serial
6868
name: "ServoR",
6969
type: Ossia.Type.Int,
7070
min: 0,
71-
max: 150,
71+
max: 90,
7272
access: Ossia.Access.Set,
7373
bounding: Ossia.Bounding.Clip,
7474
request: "r$val",
7575
repetition_filter: Ossia.Repetitions.Filtered
7676
},
7777
{
7878
name: "VentiloV",
79-
type: Ossia.Type.Int,
80-
min: 0,
81-
max: 255,
79+
type: Ossia.Type.Bool,
8280
access: Ossia.Access.Set,
83-
bounding: Ossia.Bounding.Clip,
8481
request: "v$val",
8582
repetition_filter: Ossia.Repetitions.Filtered
8683
},
8784
{
8885
name: "VentiloW",
89-
type: Ossia.Type.Int,
90-
min: 0,
91-
max: 255,
86+
type: Ossia.Type.Bool,
9287
access: Ossia.Access.Set,
93-
bounding: Ossia.Bounding.Clip,
9488
request: "w$val",
9589
repetition_filter: Ossia.Repetitions.Filtered
9690
},
9791
{
9892
name: "VentiloX",
99-
type: Ossia.Type.Int,
100-
min: 0,
101-
max: 255,
93+
type: Ossia.Type.Bool,
10294
access: Ossia.Access.Set,
103-
bounding: Ossia.Bounding.Clip,
10495
request: "x$val",
10596
repetition_filter: Ossia.Repetitions.Filtered
10697
}

0 commit comments

Comments
 (0)