跳转到主要内容

GR-CITRUS Special Program: Class and Method Simplified Charts

Kernal Class

SyntaxOverviewArgumentReturn Value
pinMode(pin, mode)Pin mode settingpin: Pin number
mode: Set the following values:
0 (INPUT)
1 (OUTPUT)
2 (INPUT_PULLUP)
3 (OUTPUT_OPENDRAIN)
Version
digitalWrite(pin, value)Set pin output to 0 or 1pin: Pin number
value: 0 or 1
None
digitalRead(pin)Check whether pin input is 0 or 1pin: Pin number0 or 1
analogRead(pin)Confirm analog value of pinpin: Pin number (14, 15, 16, 17)0 to 675 (3.3V)
Input mode can be specified in analogReference, as described below.
analogReference(mode)Specify analogRead input modemode: Select from the following:
0: 5.0V ref.
1: 1.1V ref. (built-in voltage)
2: 3.3V ref.
3: 3.3V ref., 12-bit resolution (0 to 4096)
None
pwm(pin, value)PWM output from pin (490Hz)pin: Pin number
value: PWM rate 0 to 255
None
initDac()Initialize DA converterNoneNone
analogDac(value)Output analog value from DAC pin0 to 4096 (3.3V)None
led(value)Set LED outputvalue: 0(OFF) or 1(ON)None
delay(value)Wait for specified timevalue: Time ((ms))None
millis()Count time period in millisecond from system startup. Overflows and returns to 0 after about 50 days.NoneMilliseconds
micros()Count time period in microseconds from system startup. Overflows and returns to 0 after about 1 week.NoneMicroseconds
tone(pin, frequency[, duration)Output tone signal used for piezoelectric sounder, etc.pin: Pin number, frequency, duration, output time (option)None
noTone(pin)Stop tone signal outputpin: Pin numberNone
randomSeed(value)Set random seedvalue: The value to be used as the random seedNone
random([min,] max)Get random countmin: Minimum value (option),
max: Maximum value
Random

System Class

SyntaxOverviewArgumentReturn Value
System.version([R])Get system versionAny valueVersion
System.exit()End program. If the program was set by System.setrun, that program will be executed.NoneNone
System.setrun(file)Set next program to be executed.file name: mrbNone
System.push(address, buf, length)Store value in flash memory. The value will not be erased even when the power is turned off.address: Start address (0 to 255)
buf: Write data
length: Data length (Max. 32 bytes)
0: Failure, 1: Success
System.pop(address, length)Get value from flash memoryaddress: Start address (0 to 255)
length: Data length (Max. 32 bytes)
Amount of data retrieved
System.useSD()Set to enable use of SD cardNone0: Invalid, 1: Valid
System.useWiFi()Set to enable use of WA-MIKAN (ESP8266 board)None0: Invalid, 1: Valid
System.getMrbPath()Get file path of mrb now runningNoneFile path (file name)

Serial Class

This class generates and uses an instance for each communication port.

SyntaxOverviewArgumentReturn Value
serial.new(num,bps)Serial communication initializationnum: Communication port to be initialized (TX/RX)
0: USB, 1: 0/1, 2: 5/6, 3: 7/8, 4: 12/11
bps: Baud rate
Serial instance
serial.print([str])Output to serial portstr: Output stringNone
serial.println([str])Output to serial port with line break
Line break: \r\n
str: Output string
When omitted, only line break
None
serial.write(buf, len)Data outputbuf: Output data string, len: Data countOutput data count
serial.flush()Wait until transmission is completedNoneNone
serial.available()Check if receive data is availableNoneNumber of bytes of data
0: No data
serial.read()Get dataNoneString or receive data

I2C Class

This class generates and uses an instance for each communication port.

SyntaxOverviewArgumentReturn Value
i2c.new(num)I2C communication initializationnum: Communication port to be initialized (SDA/SCL)
0: 18/19, 1: 0/1, 2: 5/6, 3: 7/8, 4:12/11
I2C instance
i2c.begin(address)Start I2C write preparationaddress: Device 7-bit addressNone
i2c.lwrite(data)Write to I2C write bufferdata: DataNone
i2c.end()Execute prepared I2C write communicationNoneNone
i2c.request(address, count)Execute a read request to the deviceaddress: 7-bit address
count: Data count
Receive data count
i2c.available()Check if receive data is availableNoneReceive data count
0: None
i2c.lread()Get receive dataNoneReceive data
i2c.write(address, reg, data)Write 1 byte to the device specified address (execute begin, lwrite, end)address: 7-bit address
reg: Write address in device
data: Data
Always 0
i2c.read(address, regL[, regH])Read data from device specified address (execute write, request, read)address: 7-bit address
regL: Read lower address
regH: Read upper address (option)
Read data

Servo Class

SyntaxOverviewArgumentReturn Value
Servo.attach(ch, pin [, min, max] )Assign output pin to servo motor to specified channelch: Any channel (0 to 9)
pin: Any pin
min: Pulse width at 0 degrees (default = 544µs) (option)
max: Pulse width at 180 degrees (default = 2400µs) (option)
I2C instance
Servo.write(ch, angle)Set anglech: Channel (0 to 9)
angle: 0 to 180
None
Servo.read(ch)Get current anglech: Channel (0 to 9)Angle
Servo.us(ch, us)Set angle with pulse widthch: Channel (0 to 9)
us: 0 to 19999
None
Servo.attached(ch)Check if servo is assigned to channelch: Channel (0 to 9)0: Not assigned
1: Assigned
Servo.detach(ch)Release servo assignmentch: Channel (0 to 9)None

Rtc Class

SyntaxOverviewArgumentReturn Value
Rtc.init()Start real time clockNone0: Failure
1: Success
Rtc.deinit()Stop real time clockNone0: Failure
1: Success
Rtc.setTime(array)Set timearray: year (0000-9999), month (1-12), date (1-31), hour (0-23), minute (0-59), second (0-59)0: Failure
1: Success
Rtc.getTime()Get timeNoneThe following array:
year: (2000-2099)
month: (1-12)
day: (1-31)
hour: (0-23)
minute: (0-59)
second: (0-59)
weekday: (0-6) 0: SUN, 1: MON, 2: TUES, 3: WED, 4: THUR, 5: FRI, 6: SAT

SD Class

System.useSD() must be called before using this class.

SyntaxOverviewArgumentReturn Value
SD.open(number, filename[, mode])Open the filenumber: Any file number (0 or 1)
filename: File name (8.3 format)
mode: 0: Read, 1: Append, 2: New Create
File number
-1 = Failure
SD.close(number)Close the filenumber: File numberNone
SD.seek(number, byte)Move to the position in the file to be readnumber: File number
byte: Move toward end of file for the number of bytes (-1) required by seek
0: Failure
1: Success
SD.read(number)Read from the filenumber: File numberData (bytes)
If position is the end of the file, -1 is returned.
SD.write(number,buf,len )Write to the filenumber: File number
buf: Data buffer
len: Data count
Number of data written
SD.flush(number)Wait for write operation to completenumber: File numberNone
SD.size(number)Get file sizenumber: File numberSize
SD.position(number)Get read/write positionnumber: File numberPosition
SD.mkdir(dirname)Create directorydirname: Name of directory to be created0: Failure
1: Success
SD.rmdir(dirname)Delete directorydirname: Name of directory to be deleted0: Failure
1: Success
SD.remove(filename)Delete filefilename: Name of file to be deleted0: Failure
1: Success
SD.copy(srcfilename, distfilename)Copy filesrcfilename: Name of source file to be copied
distfilename: Name of destination file to be copied to
0: Failure
1: Success
SD.exists(filename)Check if file existsfilename: Name of file to be checked0: No file
1: File exists

WiFi Class

SyntaxOverviewArgumentReturn Value
WiFi.setMode(mode)Set station modemode:
1: Station
2: SoftAP
3: Station + SoftAP1
ESP8266 return value
WiFi.ipconfig()Display IP address and MAC addressNoneESP8266 return value
WiFi.connect(SSID, Passwd)Connect to WiFi access pointSSID: WiFi SSID
Passwd: Password
ESP8266 return value
WiFi.multiConnect(mode)Set mode for multiple connectionsmode:
0: Connect 1 only1
1: Connect up to 4
ESP8266 return value
WiFi.disconnect()Disconnect WiFiNoneESP8266 return value
WiFi.httpGetSD(Filename, URL[, Headers])Store http GET results on SD cardFilename: Name of file to be stored
URL: URL
Headers: An array of character strings to be added to header
0: Failure
1: Success
2: SD card use invalid
3: Couldn’t open transmit data file
4: Couldn’t read transmit data size
5: Couldn’t read transmit data file
6: Couldn’t open receive data file
7: Failure to create received file
WiFi.httpGet(URL[, Headers])Transmit http GET protocol.
Only transmit, do not receive.
URL: URL
Headers: An array of character strings to be added to header
0: Failure
1: Success
WiFi.httpPost(URL, Header, Body)Transmit http POST protocolURL: URL
Header: An array of character strings to be added to header
Body: An array of character strings to be added to body
0: Failure
1: Success
WiFi.httpServer([port])Start http server; SD card is requiredport: The number of the port waiting for data; if -1 is specified, the server stops.One of the following values is returned depending on access availability:
0: No access
1: Access available
2: Cannot use SD card
3: Failed to access SD card

For access from client:
GET: Path
Other than GET: First line of header
WiFi.udpOpen(number, IPAddress, SendPort, ReceivePort)Start UDP connectionnumber: Connection number (1 to 4)
IPAddress: Communication destination address
SendPort: Communication port number
ReceivePort: Receive port number
ESP8266 return value
WiFi.send(number, Data[, length])Transmit data to specified connection numbernumber: Connection number (1 to 4)
Data: Data to be transmitted
length: Size of data to be transmitted
Transmit data size
WiFi.recv(number)Receive data from specified connection numbernumber: Connection number (1 to 4)Array of received data; must be 256 or less
WiFi.cClose(number)Close TCP/UDP connectionnumber: Connection number (1 to 4)ESP8266 return value
WiFi.bypass()Direct serial connection between USB port and ESP8266.
Processing does not return until reset occurs.
NoneNone
WiFi.serialOut(mode[, serialNumber])Set serial number for serial output to ESP8266mode:
0: No output
1: Output
serialNumber: Serial number of output destination
None
WiFi.at(command[, mode])Transmit AT command to ESP8266command: AT command string
mode:
0: Automatically add 'AT+'
1: Do not automatically add 'AT+'
ESP8266 return value