Базовое программирование с помощью IC10
GHub Platform · Гайд · 0 ответов · 19 просмотров

To start working with IC10, you will need some basic equipment: Computer IC Editor motherboard IC Housing IC10 chip (place inside housing) The IC Housing's data port should be connected to the Computer's data port, and both should be powered. For simplicity I just wire them all together on a separate network. You can separate a network from the rest of your base by putting a power controller in between. If both are properly connected and powered on, you will see the dropdown on the top left of the Computer screen read "IC Housing" or whatever you have labeled the housing. Note the two other buttons: "Import" and "Export". The code that you write in the computer is stored separately and does NOT automatically get transferred to the IC10 chip currently in the housing. Clicking on "Import" will load the code from the chip into your computer, overwriting what you have in the editor. Clicking on "Export" will write the code from your computer onto the chip. Don't forget to hit Export whenever you are done tweaking your code. Finally, click the "Edit" button at the bottom-right of the screen to open up the code editor. Let's dive straight into things. Don't worry about all the buttons for now. To understand code, let's start with its structure. Code is written as a series of lines, one after the other. Note the line numbers at the left side of the screen. It is read from top to bottom. Always keep in mind that that is exactly what the computer does as well. It first reads line 0 and does what that line tells it to do, then goes on to the next line and does what that line tells it to do. Sometimes, a line will tell the computer to jump to a different line instead of the next one. The computer will then read that line it jumped to, do what it says, then move on to the next line, and so on and so forth. When in doubt, always start at line 0, and slowly work your way through your program line by line. Follow the computer's train of thought and you will always be able to discover your mistakes. Note that some words are in different colours. Each of these colours mean something special. They are a great way to help you understand how the computer is interpreting what you have written. Yellow words are functions . They tell the computer to perform a specific action. Oftentimes you will need to give a function some additional information, or arguments . White words are names . These help you remember what role you've assigned various devices and registers. Green words are device ports . They correspond to specific connections on the IC10 housing , and are how you connect the chip to other things on the network such as sensors, heaters and coolers, and so on. Orange words are device variables . They correspond to specific pieces of information that a device collects or uses, and they differ from device to device. For example, you can edit Horizontal and Vertical on solar panels to control where they are facing, while you can read Temperature and Pressure from gas sensors. Blue words are registers . They function as temporary memory, places to store numbers that you're currently working with. For example, when you load the temperature from a gas sensor, you will first need to store it in a register if you want to compare it with something else. Teal words are values . They are simple numbers and mean what they look like they mean. Purple words are labels . Instead of telling a computer to jump to a specific line, we can tell it to jump to a label instead. This greatly helps us organize our code by giving names to specific parts of it. Red words are errors. Most of the time, you entered something wrong. However, sometimes the editor doesn't recognize labels properly. Finally, note the three buttons on the top right hand side of the editor. Those are reference lists that can help you out when you're not sure what order to write your arguments in for example. The most important one is "f", which is a list of functions and the arguments they take. When you connect an IC10 housing to a network, it does not automatically recognize other devices on the network. In order to be able to talk to them in your code, you need to link them to the device ports on the IC10 housing. This is done by holding a screwdriver and adjusting the screws on the housing. When you hover over each screw, you can see the name of the device that the port is currently connected to, and which one you will switch to if you click on the screw again. Note that if you have renamed the device ports in your code with the alias function, you will see the port's name when you hover on it. Similarly, if you have renamed your devices with the labeler, you will see the device's new name when you are adjusting the ports. Throughout this section, I'll refer to the example script posted above, and only that one. The line numbers and section labels will always be the same. This script controls a bunch of liquid wall coolers to keep the temperature between 20 degrees Celsius and 25 degrees Celsius. Let's start from the very top and work our way down line by line. 0. alias Sensor d0 The alias function simply assigns a name to something such as a device or a register. It is however one of the most useful functions you can use, since it greatly helps organization. In this case we are assigning the name "Sensor" to d0. Remember the previous section on devices? D0 is the device that is connected to the top left of the IC housing. In this case, we are giving the device connected to that slot the nickname "Sensor". Note that alias does not actually rename the device that is connected to the slot. You must manually use a labeler to do that. Alias is purely for use inside the code you are writing. 1. alias CurrTemp r0 Another use of alias. However we are assigning a name to a register . Think of a register like a memo pad. It stores information for temporary use. In this case, we are going to use it to store the temperature that we get from the sensor, and so we call it "CurrTemp", or current temperature. 2. alias MaxTemp r1 3. alias MinTemp r2 4. alias SetOn r3 5. alias SetOff r4 In these lines, we are assigning a few more names to registers that we will use in the program. These are the maximum and minimum temperatures that we want in the room, and the values that we need to store onto a device in order to tell it to turn on and off. 6. add MaxTemp 273 25 Here we get the first real math in the program. Let's break it down. First though, let's take a look at the description of the function add in the editor's own reference guide. If that seems confusing, don't worry. It's quite simple once you break it down. add r? a ( r? | num ) b ( r? | num ) Register = a + b. The first line describes how you use the function in your code. In this case, you type "add" first. Then you specify the register (r?). Then you specify a, and finally you specify b. The first register you specify is the location where you want to store the result. Remember that registers are memo pads where you store information. The result of adding two numbers together is useful, but if you want to use it, you need to store it somewhere- usually a register. a(r? | num) means that "a" can be either a register or a number. If you specify a register, add will take the number stored in the register. The same goes for "b". Remember that registers are memo pads that store information. Most of the time, registers will store a number. So if register 4 stores the number 15, and register 5 stores the number 3, then: add r0 r4 r5 Means that you want to add the number in r4 to the number in r5 and store the result in r0. After this line, r0 will contain the number 18. Similarly: add r0 r4 6 Means that you want to add the number in r4 to the number 6 and store the result in r0. After this line, r0 will contain the number 21. In the example cod
ИсточникGHub Platform · автор30.08.2026, 23:27:09
To start working with IC10, you will need some basic equipment: Computer IC Editor motherboard IC Housing IC10 chip (place inside housing) The IC Housing's data port should be connected to the Computer's data port, and both should be powered. For simplicity I just wire them all t…
Войдите, чтобы писать в группе