Не работает код

Тема в разделе "Флудилка", создана пользователем Джама Омаров, 3 сен 2016.

  1. Добрый день!

    Есть Образовательный набор «Амперка», установил программу Arduino с официального сайта, работаю на Mac, примеров от Амперки нет (но это и не важно), застрял на параграфе 13.3 "Как научить компьютер говорить на азбуке Морзе при помощи Arduino", дело вот в чем:

    Я переписал код с книги:

    int soundPin = 13;
    int dotDelay = 50;

    long time;
    int rate = 100;

    void sound(int duration)
    {
    time = millis();
    while (millis() - time < duration) {
    digitalWrite(soundPin, HIGH);
    delayMicroseconds(rate);
    digitalWrite(soundPin, LOW);
    delayMicroseconds(rate);
    }
    }


    void dot()
    {
    sound(dotDelay);
    delay(dotDelay);
    }

    void dash()
    {
    sound(3 * dotDelay);
    delay(3 * dotDelay);
    }

    void letterEnd()
    {
    delay(2 * dotDelay);
    }

    void wordEnd()
    {
    delay(6 * dotDelay);
    }

    void morseLetter(char c)
    {
    switch (c) {
    case "a": dot(); dash(); break;
    case "b": dash(); dot(); dot(); dot(); break;
    case "c": dash(); dot(); dash(); dot(); break;
    case "d": dash(); dot(); dot(); break;
    case "e": dot(); break;
    case "f": dot(); dot(); dash(); dot(); break;
    case "g": dash(); dash(); dot(); break;
    case "h": dot(); dot(); dot(); dot(); break;
    case "i": dot(); dot(); break;
    case "j": dot(); dash(); dash(); dash(); break;
    case "k": dash(); dot(); dash(); break;
    case "l": dot(); dash(); dot(); dot(); break;
    case "m": dash(); dash(); break;
    case "n": dash(); dot(); break;
    case "o": dash(); dash(); dash(); break;
    case "p": dot(); dash(); dash(); dot(); break;
    case "q": dash(); dash(); dot(); dash(); break;
    case "r": dot(); dash(); dot(); break;
    case "s": dot(); dot(); dot(); break;
    case "t": dash(); break;
    case "u": dot(); dot(); dash(); break;
    case "v": dot(); dot(); dot(); dash(); break
    case "w": dot(); dash(); dash(); break;
    case "x": dash(); dot(); dot(); dash(); break;
    case "y": dash(); dot(); dash(); dash(); break;
    case "z": dash(); dash(); dot(); dot(); break;
    case " ": wordEnd(); break;
    }
    letterEnd();
    }

    void setup()
    {
    pinMode(soundPin, OUTPUT);
    Serial.begin(9600);
    }

    void loop()
    {
    if (Serial.available() > 0) {
    char c = Serial.read();
    morseLetter(c);
    }
    }


    А программа выдает ошибку
     
  2. Вот ошибка:
    Arduino: 1.6.11 (Mac OS X), Board: "Arduino/Genuino Uno"

    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino: In function 'void morseLetter(char)':
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:46:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "a": dot(); dash(); break;
    ^
    sketch_aug24a:46: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:47:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "b": dash(); dot(); dot(); dot(); break;
    ^
    sketch_aug24a:47: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:48:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "c": dash(); dot(); dash(); dot(); break;
    ^
    sketch_aug24a:48: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:49:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "d": dash(); dot(); dot(); break;
    ^
    sketch_aug24a:49: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:50:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "e": dot(); break;
    ^
    sketch_aug24a:50: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:51:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "f": dot(); dot(); dash(); dot(); break;
    ^
    sketch_aug24a:51: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:52:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "g": dash(); dash(); dot(); break;
    ^
    sketch_aug24a:52: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:53:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "h": dot(); dot(); dot(); dot(); break;
    ^
    sketch_aug24a:53: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:54:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "i": dot(); dot(); break;
    ^
    sketch_aug24a:54: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:55:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "j": dot(); dash(); dash(); dash(); break;
    ^
    sketch_aug24a:55: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:56:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "k": dash(); dot(); dash(); break;
    ^
    sketch_aug24a:56: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:57:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "l": dot(); dash(); dot(); dot(); break;
    ^
    sketch_aug24a:57: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:58:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "m": dash(); dash(); break;
    ^
    sketch_aug24a:58: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:59:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "n": dash(); dot(); break;
    ^
    sketch_aug24a:59: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:60:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "o": dash(); dash(); dash(); break;
    ^
    sketch_aug24a:60: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:61:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "p": dot(); dash(); dash(); dot(); break;
    ^
    sketch_aug24a:61: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:62:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "q": dash(); dash(); dot(); dash(); break;
    ^
    sketch_aug24a:62: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:63:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "r": dot(); dash(); dot(); break;
    ^
    sketch_aug24a:63: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:64:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "s": dot(); dot(); dot(); break;
    ^
    sketch_aug24a:64: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:65:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "t": dash(); break;
    ^
    sketch_aug24a:65: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:66:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "u": dot(); dot(); dash(); break;
    ^
    sketch_aug24a:66: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:67:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "v": dot(); dot(); dot(); dash(); break
    ^
    sketch_aug24a:67: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    sketch_aug24a:68: error: expected ';' before 'case'
    case "w": dot(); dash(); dash(); break;
    ^
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:68:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "w": dot(); dash(); dash(); break;
    ^
    sketch_aug24a:68: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:69:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "x": dash(); dot(); dot(); dash(); break;
    ^
    sketch_aug24a:69: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:70:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "y": dash(); dot(); dash(); dash(); break;
    ^
    sketch_aug24a:70: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    /Users/Dzhamaluddin/Documents/Arduino/sketch_aug24a/sketch_aug24a.ino:71:10: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
    case "z": dash(); dash(); dot(); dot(); break;
    ^
    sketch_aug24a:71: error: conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression
    exit status 1
    conversion from pointer type 'const char (*)[2]' to arithmetic type 'int' in a constant-expression

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
     
  3. DIYMan

    DIYMan Guest

    Уберите двойные кавычки вокруг всех символов в case, и замените их на одинарные, т.е., было -
    Код (C++):
    case "b"
    должно стать
    Код (C++):
    case 'b'
     
    Tomasina нравится это.
  4. Спасибо огромное!