Articles Posted in the " " Category

  • Variables (程式变数)

    Variables (程式变数)

    变数是用来储存资料的地方,它有名字、型别、数值;举个例子,下面这行指令 (又称为 宣告):    int pin = 13; 创建一个名为 pin 的变数,数值为 13,资料型别为 int;后面的程式码你可以透过它的名字来使用这个变数,在使用变数时程式会自动去找出它的值;举个例子,像这个状况:    pinMode(pin, OUTPUT); 变数的好处是你只需要指定一次脚位数字就可以一直去使用它,假如你之后决定要把 pin 13 改为 pin 12 的话你只需要改变一点点程式码即可。你也可以利用语意较清楚的描述来作为变数的名字,使变数所代表的意义更加明确 (例:一支程式控制 RGB LED 的变数叫做 redPin、greenPin、bluePin)。 另外,变数还有比单纯使用一个数字方便的优点:那就是你可以用 指派 的方式去改变一个变数的数值 (以等号表示),举个例子:    pin = 12; 这会把变数的值改变成 12,注意这边并没有指明变数的资料型别,也没有因为指派数值而改变资料型别。变数会永久保持原本的资料型别,只有它的数值会改变 (注:只有在一些语言中有支援,像是 Python,它的资料型别会随着它的数值变化,而不是随变数名称,所以你可以指派任何型别的数值给同一变数,这称为 动态型别;但在 86Duino 和 Arduino 中不支援动态型别功能) 注意:你必须要先宣告变数才可以去指派数值给它,如果你在使用变数之前没有先宣告的话,将会得到以下的讯息:” error: pin was not declared in this scope”。 当你指派变数给另一个变数,你只是复制它的数值到另一个变数的记忆体位置,改变其中一个不会对另一个有影响,举个例子: […]


  • Sketch 入门

    Sketch 入门

    在这个教学中,你将学习到草稿码各部分的运作方式。 草稿码 草稿码(sketch)是 Arduino 与 86Duino 用来称呼一支程式的方式,它是一个上传和运行在 Arduino、86Duino 板上的程式单元。 注解 Blink 草稿码的头几行是 注解: Arduino/86Duino 在运行草稿码时,在 /* 和 */ 之间的每一行叙述都会被忽略 (每一行叙述前面都有一个 *,那只是为了美观,并不是必需的),对阅读草稿码的人来说,注解用来解释这个程式是做什么、是怎么做的、又或者是为何使用这种方法。修改程式码后立即加上注解是一个良好的习惯,好的注解可以帮助你花较少的时间了解程式码的用意,也可以让其他人学习或修改你的程式码。 另一种简洁的注解方式,以 // 开头并且注解一整行;例如:    int ledPin = 13; // LED 连接到数位 pin13 以上的 LED 连接到数位 pin13 这行讯息就是注解 变数 变数 是用来储存数据的地方。它有名字、型态、数值。Blink 草稿码中有一行宣告变数名为 ledPin、型态是 int、初始数值是 13。它用来指示 Arduino / 86Duino 哪一个脚位与 LED 灯相连,在草稿码中每写一次 ledPin,它的值就会被取出来使用。事实上在这个例子中,不一定要创建一个名为 ledPin 的变数,可以直接写 13 […]


  • == 运算子

    == 运算子

    描述 比较两个字串是否相等。比较过程中会区分大小写,所以字串 hello 和字串 HELLO 是不同的。与 String.equals() 的功能是相同的。 语法 string1 == string2 参数 string,string2:String 物件 (字串) 回传 true: 假如 string1 与 string2 相等 false: 与上面结果相反 范例 - StringComparisonOperators See also - String - equals() - equalsIgnoreCase() - compareTo() 语法参考主页面 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed […]


  • + 运算子

    + 运算子

    描述 结合两个字串成为一个新字串。第二组字串会接在第一组字串后面。与呼叫 String.concat() 的结果相同。 语法 string3 = string1 + string 2; string3 += string2; 参数 string,string2,string3:String 物件 (字串) 回传 两个字串结合过后的新字串 范例 - StringAppendOperator See also - String - String Addition operator 语法参考主页面 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. […]


  • [] (存取字元元素)

    [] (存取字元元素)

    描述 允许去取得字串中的字元。 语法 char thisChar = string1[n] 参数 thisChar (char 型别) 字元变数 string1 String 物件 (字串) n (int 型别) 数字变数 回传 字串中第 n 个字元。与呼叫 charAt() 的结果相同。 范例 - StringCharacters See also - String - charAt() 语法参考主页面 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative […]


  • trim()

    trim()

    描述 得到一个去除头尾空白的字串。 trim() 会修改原字串而不是回传转换后的新字串。 语法 string.trim() 参数 string : String 物件 (字串) 回传 无回传值 范例 - StringLengthTrim See also - String 语法参考主页面 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public […]


  • toUpperCase()

    toUpperCase()

    描述 把字串中的英文字母转换成大写。 toUpperCase() 会修改原字串而不是回传转换后的新字串。 语法 string.toUpperCase() 参数 string : String 物件 (字串) 回传 无回传值 范例 - StringCaseChanges See also - String - toLowerCase() 语法参考主页面 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into […]


  • toLowerCase()

    toLowerCase()

    描述 把字串中的英文字母转换成小写。 toLowerCase() 会修改原字串而不是回传转换后的新字串。 语法 string.toLowerCase() 参数 string : String 物件 (字串) 回传 无回传值 范例 - StringCaseChanges See also - String - toUpperCase() 语法参考主页面 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into […]


  • toInt()

    toInt()

    描述 把字串转换成一个整数。输入的字串应该要以整数数字开头,假如字串中包含非整数的数字,这个函式即停止转换。 语法 string.toInt() 参数 string : String 物件 (字串) 回传 long 型别 (假如这个字串是因为开头不是整数数字而不能被转换,则回传 0) 范例 - StringToIntExample See also - String 语法参考主页面 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the […]


  • toCharArray()

    toCharArray()

    描述 复制字串中的字元到指定的阵列。 语法 string.toCharArray(buf, len) 参数 string : String 物件 (字串) buf : 指定的阵列 (char [] 型别) len : 阵列大小 (unsigned int 型别) 回传 无回传值 See also - String - getBytes() 语法参考主页面 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. […]