/
sculpture.c
114 lines (101 loc) · 2.43 KB
/
sculpture.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* =====================================================================================
*
* Filename: sculpture.c
*
* Description: 7x7 musical sculpture
*
* Version: 1.0
* Created: 01/17/16 01:17:39
* Revision: none
* Compiler: gcc
*
* Author: David Ferreira (df), david.io.ferreira@gmail.com
* Organization:
*
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#include <mcp3004.h>
#include "player.h"
#include "volume.h"
#define BASE 100
#define SPI_CHAN 0
#define buttonA_pin 5
#define buttonB_pin 6
#define buttonC_pin 13
#define buttonD_pin 26
#define ultrasound_pin 100
#define ir_pin 101
void sculpture_start() {
printf("\n\n***7x7 sculpture wait for signal***\n\n");
for (;;) {
int x = analogRead(ultrasound_pin);
int vol_min = 30, vol_max = 85;
// button(vol_min,vol_max);
if (x<100) {
play_track();
volume_set(vol_max);
sculpture_play(vol_min, vol_max);
}
printf("ultrasound = %d\n",x);
delay(200);
}
}
void sculpture_play(int min, int max) {
printf("\n\n***7x7 sculpture play***\n\n");
for (;;) {
int x = analogRead(ultrasound_pin);
// button(min, max);
if (x>100) {
for (int i=0; i<15; i++) {
int x = analogRead(ultrasound_pin);
printf("counter = %d\n",i);
// button(min, max);
if (x<100) {
sculpture_play(min, max);
}
delay(1000);
}
volume_down(min, max);
pause_track();
sculpture_release(min,max);
}
printf("ultrasound = %d\n",x);
delay(200);
}
}
void sculpture_release(int min, int max) {
printf("\n\n***7x7 sculpture release***\n\n");
for (;;) {
int x = analogRead(ultrasound_pin);
// button(min, max);
if (x<100) {
release_track();
volume_up(min, max);
sculpture_play(min, max);
}
printf("ultrasound = %d\n",x);
delay(50);
}
}
void button(int min, int max) {
if (digitalRead(buttonA_pin) == 1) {
//volume_set(max);
//play_track();
printf("\nbutton A\n");
}
if (digitalRead(buttonB_pin) == 1) {
printf("\nbutton B\n");
max = volume_set(max+1);
}
if (digitalRead(buttonC_pin) == 1) {
printf("\nbutton C\n");
}
if (digitalRead(buttonD_pin) == 1) {
printf("\nbutton D\n");
max = volume_set(max-1);
}
}