Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   AnalogReadSerial
  3.  
  4.   Reads an analog input on pin 0, prints the result to the Serial Monitor.
  5.   Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
  6.   Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
  7.  
  8.   This example code is in the public domain.
  9.  
  10.   http://www.arduino.cc/en/Tutorial/AnalogReadSerial
  11. */
  12.  
  13. const int LED_PIN = 8;
  14. const int BUZZER_PIN = 3;
  15.  
  16. const int DELAY_CRTA = 1000;
  17. const int DELAY_TACKA = 100;
  18.  
  19. char poruka[]="SOS";
  20. char morze[26][5]={
  21.     ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....",
  22.     "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.",
  23.     "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-",
  24.     "-.--", "--.."
  25. };
  26.  
  27.  
  28. void beep(unsigned char delayms) { //creating function
  29.   analogWrite(BUZZER_PIN, 20); //Setting pin to high
  30.   delay(delayms); //Delaying
  31.   analogWrite(BUZZER_PIN ,0); //Setting pin to LOW
  32.   delay(delayms); //Delaying
  33.  
  34. }
  35. // the setup routine runs once when you press reset:
  36. void setup() {
  37.   Serial.begin(9600);
  38.   pinMode(LED_PIN,OUTPUT);
  39.  
  40.   pinMode(BUZZER_PIN, OUTPUT); //Set buzzerPin as output
  41.   beep(50); //Beep
  42.   beep(50); //Beep
  43.   delay(1000); //Add a little delay
  44. }
  45.  
  46. void epilepsija(int pin){
  47.   for(int i=0;i<10;i++){
  48.     delay(40);
  49.     beep(40);
  50.     digitalWrite(pin,HIGH);
  51.     delay(40);
  52.     beep(40);
  53.     digitalWrite(pin,LOW);
  54.   }
  55. }
  56.  
  57. // the loop routine runs over and over again forever:
  58. void loop() {
  59.   for(int i=0;i<sizeof(poruka)-1;i++){
  60.     char slovo = poruka[i];
  61.     Serial.print(slovo);
  62.     Serial.print(':');
  63.     for(int j=0; morze[slovo - 'A'][j]!='\0';j++){
  64.       char znak = morze[slovo - 'A'][j];
  65.       Serial.print(znak);
  66.       digitalWrite(LED_PIN,HIGH);
  67.       if(znak=='.')
  68.         beep(DELAY_TACKA);
  69.       else
  70.         beep(DELAY_CRTA);
  71.       digitalWrite(LED_PIN,LOW);
  72.       delay(200);
  73.     }
  74.     Serial.println();
  75.     delay(200);
  76.   }
  77.   Serial.println(' ');
  78.   epilepsija(LED_PIN);
  79.   delay(2000);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement