Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ASCII
- //SPACE-32
- //UNDERSCORE-95
- // include the library code:
- #include <LiquidCrystal.h>
- #include <IRremote.h>
- const int joy1X = 0;
- const int joy1Y = 2;
- const int joy2X = 4;
- const int joy2Y = 6;
- const int buttonSpace = 46;
- const int buttonEnter = 47;
- const int buttonSend = 44;
- const int IRRecPin = 45;
- const int IRSenPin = 43;
- IRsend irsend;
- IRrecv irrecv(IRRecPin); // Receive on pin 45
- decode_results results;
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(48, 49, 50, 51, 52, 53); //lcd(12, 11, 5, 4, 3, 2);
- int qwe;
- int gloo;
- bool monom;
- char uSc = ((char)95);
- char mes[16];
- char rec[16];
- bool isSending=false;
- void setup() {
- qwe = 0;
- gloo = 0;
- monom = false;
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- // Print a message to the LCD.
- Serial.begin(9600);
- pinMode(7, INPUT);
- pinMode(8, INPUT);
- pinMode(9, INPUT);
- mes[0] = uSc;
- for (int q = 1; q < 16; q++) {
- mes[q] = (char)32;
- }
- irrecv.enableIRIn(); // Start the receiver
- lcd.setCursor(0, 0);
- lcd.print("ENTER - send");
- lcd.setCursor(0, 1);
- lcd.print("SPACE - receive");
- bool hasChosen=false;
- do{
- delay(10);
- if(digitalRead(buttonEnter)==HIGH){
- isSending=true;
- hasChosen=true;
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Sending");
- }
- if(digitalRead(buttonSpace)==HIGH){
- isSending=false;
- hasChosen=true;
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Receiving");
- }
- }while(!hasChosen);
- delay(2000);
- lcd.clear();
- }
- void loop() {
- if(isSending){
- lcd.clear();
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- lcd.setCursor(0, 1);
- // print the number of seconds since reset:
- lcd.print(mes);
- lcd.setCursor(8, 0);
- lcd.print((int)analogRead(8));
- lcd.setCursor(0, 0);
- lcd.write(potType());
- //lcd.print(nunu);
- delay(200);
- gloo++;
- if (gloo % 5 == 0) {
- monom = true;
- }
- if (digitalRead(buttonSend) == HIGH) { //SEND
- int err = sendMes();
- while (err == 13) {
- Serial.println("FAILED TO INITIALIZE RECIEVER");
- sendMes();
- }
- while (err == 14) {
- Serial.println("FAILED CHECKSUM TEST");
- sendMes();
- }
- }
- if (digitalRead(buttonEnter) == HIGH){
- mes[qwe] = potType();
- mes[qwe + 1] = uSc;
- qwe++;
- }
- if(digitalRead(buttonSpace)==HIGH){
- mes[qwe]=' ';
- mes[qwe+1]=uSc;
- qwe++;
- }
- }else{ //Rec
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("WAITING");
- Serial.println("WAITING FOR INIT CODE");
- while (!irrecv.decode(&results));
- Serial.println("CODE RECIEVED");
- lcd.clear();
- int erro;
- Serial.println("ATTEMPTING TO RECIEVE MESSAGE");
- while(erro!=30){
- erro = recMes();
- }
- lcd.setCursor(1,0);
- lcd.print("ENTER TO RESTART");
- while(digitalRead(47)==LOW);
- }
- }
- char potType(){
- char readr;
- int ono = analogRead(8);
- int non = map(ono, 0, 1030, 90, 64);
- readr=(char)non;
- return(readr);
- }
- int sendMes() {
- lcd.clear();
- lcd.setCursor(1,0);
- lcd.print(mes);
- lcd.setCursor(0,0);
- lcd.print("TRANSMITTING");
- irsend.sendSony(0x0000, 12);
- Serial.println("INITIALIZING TRANSMISSION");
- irsend.sendSony(0x0000, 12);
- lcd.print(".");
- while (!irrecv.decode(&results));
- if (irrecv.decode(&results)) {
- Serial.println(results.value, HEX);
- irrecv.resume(); // Continue receiving
- }
- lcd.print(".");
- if (results.value != 0xFFFF) {
- return (13);
- }
- Serial.println("INITIALIZATION SUCCESSFUL");
- Serial.println("BEGINNING TRANSMISSION");
- for (int i = 0; i < 16; i++) {
- Serial.print("TRANSMITTING BYTE ");
- Serial.println(i);
- int msg = (int)(mes[i]);
- Serial.println(msg);
- irsend.sendSony(msg, 12);
- }
- Serial.println("MESSAGE TRANSMISSION COMPLETE");
- Serial.println("SENDING CHECKSUM");
- int chkSm;
- for (int i = 0; i < 16; i++) {
- chkSm += ((int)(mes[i]));
- }
- Serial.print("CHECKSUM: ");
- Serial.println(chkSm);
- irsend.sendSony(chkSm, 12);
- while (!irrecv.decode(&results));
- if (irrecv.decode(&results)) {
- Serial.println(results.value, HEX);
- irrecv.resume(); // Continue receiving
- }
- if (results.value != 0xFFFF) {
- return (14);
- }
- Serial.println("SENDING COMPLETE");
- return (0);
- }
- int recMes() {
- Serial.println("WAITING FOR INITIALIZATION CODE");
- while (!irrecv.decode(&results));
- if (irrecv.decode(&results)) {
- Serial.println(results.value, HEX);
- irrecv.resume(); // Continue receiving
- }
- if (results.value != 0x0000) {
- return (12);
- }
- Serial.println("SENDING INITIALIZATION CONFIRMATION");
- irsend.sendSony(0xFFFF, 12);
- Serial.println("AWAITING MESSAGE");
- for (int i = 0; i < 16; i++) {
- while (!irrecv.decode(&results));
- if (irrecv.decode(&results)) {
- Serial.println(results.value, HEX);
- irrecv.resume(); // Continue receiving
- }
- rec[i] = ((char)(results.value, HEX));
- }
- int chkSm;
- for (int i = 0; i < 16; i++) {
- chkSm += ((int)(rec[i]));
- }
- while (!irrecv.decode(&results));
- if (irrecv.decode(&results)) {
- Serial.println(results.value, HEX);
- irrecv.resume(); // Continue receiving
- }
- if ((chkSm, HEX) != (results.value, HEX)) {
- return (12);
- }else{
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print(rec);
- return(30);
- }
- }
- //FINISH ADDING CHECKSUMS
- //DISPLAY REC MESSAGE
Advertisement
Add Comment
Please, Sign In to add comment