Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h>
- int RECV_PIN = 11; //Pin TSOP
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- String bindamage;
- String binid;
- int Tablica[100];
- int headwtab = 0;
- String raw = "";
- void setup()
- {
- Serial.begin(19200);
- irrecv.enableIRIn(); // Start the receiver
- standby();
- }
- void dumpCode (decode_results *results)
- {
- for (int i = 1; i < results->rawlen; i++) {
- Tablica[i] = (results->rawbuf[i] * USECPERTICK); //dodaje wartosc do Tablica
- }
- }
- void team()
- {
- String binteam;
- binteam = raw;
- binteam.remove(0,8);
- binteam.remove(2);
- if(binteam=="00") red();
- if(binteam=="01") blue();
- if(binteam=="10") yellow();
- if(binteam=="11") green();
- }
- void header() //wyszukuje miejsce headera w tablicy
- {
- for(int i = 1;i<100;i++) // wypisanie tablicy
- {
- if(Tablica[i]>2000)
- headwtab=i;
- }
- if(headwtab>0) raw.remove(0,headwtab-1);
- }
- void tobin() // zmienimy DEC na BIN
- {
- for(int i = headwtab + 2;i<100;i= i+2) // wypisanie tablicy
- {
- if(Tablica[i]>750) raw.concat(1);
- if(Tablica[i]<750) raw.concat(0);
- }
- }
- void standby()
- {
- Serial.println("standby");
- Serial.print(" ");
- // int timer=10000;
- }
- void red()
- {
- Serial.println("RED");
- }
- void blue()
- {
- Serial.println("BLUE");
- }
- void green()
- {
- Serial.println("GREEN");
- }
- void yellow()
- {
- Serial.println("YELLOW");
- }
- void isshot()
- {
- String isshot;
- isshot = raw;
- isshot.remove(1);
- if (isshot=="0") {
- Serial.println("STRZAŁ!");
- team();
- }
- }
- void loop() {
- if (irrecv.decode(&results)) {
- // Serial.println(" ");
- // Serial.println("START");
- //Serial.println(results.value, BIN);
- dumpCode(&results); // Output the results as source code
- header();
- tobin();
- isshot();
- Serial.println(raw);
- // delete [] Tablica;
- raw = "";
- headwtab = 0;
- // Serial.println("END");
- irrecv.resume(); // Receive the next value
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement