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 <SoftwareSerial.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;
- // 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);
- SoftwareSerial SerialBT(11, 12, 9600);
- 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.
- SerialBT.begin(9600);
- Serial.begin(38400);
- mes[0] = uSc;
- for (int q = 1; q < 16; q++) {
- mes[q] = (char)32;
- }
- 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();
- int erro;
- Serial.println("ATTEMPTING TO RECIEVE MESSAGE");
- while(erro!=30){
- erro = recMes();
- }
- lcd.setCursor(0,1);
- 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() {
- digitalWrite(5, HIGH);
- Serial.println("CHECKING CONNECTION");
- SerialBT.flush();
- Serial.println("SENDING MESSAGE");
- for(int i=0; i<16; i++){
- SerialBT.write((char)mes[i]);
- delay(1000);
- }
- delay(1000);
- digitalWrite(5, LOW);
- }
- int recMes() {
- Serial.println("WAITING FOR MESSAGE");
- lcd.setCursor(0,1);
- lcd.print("ENTER to Recieve");
- while(digitalRead(buttonSpace)==LOW);
- lcd.clear();
- String recm = SerialBT.readString();
- lcd.setCursor(0,0);
- lcd.print(recm);
- return(30);
- }
- //Change delay setups
- //CHANGE EVERYTHING
- //USE THE REAL SERIAL PORTS
- //FIX CONNECTING AUTOMATICALLY?
Advertisement
Add Comment
Please, Sign In to add comment