Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Queue {
- int queue[100];
- public:
- Queue(){
- for(int i = 0; i < 100; i++){
- queue[i] = 0;
- }
- }
- bool percentage(int target, int percentage){
- int per = 0;
- for(int i = 0; i < 100; i++){
- if(queue[i] == target){
- per++;
- }
- }
- return (per > percentage);
- }
- void push(int num){
- for(int i = 100; i > 0; i--){
- queue[i] = queue[i-1];
- }
- queue[0] = num;
- }
- void print(){
- for(int i = 0; i < 100; i++){
- Serial.print(queue[i]);
- Serial.print(" ");
- }
- Serial.println();
- }
- };
- int SOUNDPIN = A0;
- int DISTANCEPIN = A1;
- Queue queue;
- Queue queue2;
- bool speek = false;
- bool lastspeek = false;
- bool yell = false;
- bool closeby = false;
- bool lastcloseby = false;
- void setup() {
- //Fuck
- Serial.begin(9600);
- queue = Queue();
- queue2 = Queue();
- }
- void loop() {
- int sensor = analogRead(SOUNDPIN);
- int distance = analogRead(DISTANCEPIN);
- //Serial.println(sensor);
- if(sensor < 60){
- queue.push(2);
- }else if (sensor < 300){
- queue.push(1);
- }else{
- queue.push(0);
- }
- if(distance > 500){
- queue2.push(1);
- }else{
- queue2.push(0);
- }
- queue.print();
- if(queue.percentage(1, 2) || queue.percentage(2, 2)){
- if(queue.percentage(2, 2)){
- yell = true;
- }else{
- yell = false;
- }
- speek = true;
- }else{
- speek = false;
- yell = false;
- }
- if(queue2.percentage(1, 2)){
- closeby = true;
- }else{
- closeby = false;
- }
- if(closeby && !lastcloseby){
- Serial.println(3);
- lastcloseby = closeby;
- delay(10);
- return;
- }
- if(closeby && lastcloseby){
- lastcloseby = closeby;
- delay(10);
- return;
- }
- if(lastcloseby && !closeby){
- Serial.println(0);
- lastcloseby = closeby;
- delay(10);
- return;
- }
- if(speek && !lastspeek){
- if(!yell){
- Serial.println(1);
- }else{
- Serial.println(2);
- }
- }
- if((lastspeek && !speek)){
- Serial.println(0);
- }
- lastspeek = speek;
- lastcloseby = closeby;
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement