Arduino Night: Difference between revisions
Jump to navigation
Jump to search
Line 19: | Line 19: | ||
} | } | ||
} | } | ||
==Scooter Code== | |||
* The following code is for controlling the scooter wirelessly. | |||
struct data { | |||
byte start; | |||
byte left; | |||
byte right; | |||
byte finish; | |||
}; | |||
typedef struct data Packet; | |||
Packet myData = {0, 0x55, 0x7e, 0}; |
Revision as of 18:42, 10 March 2013
Random Code
- Writing an arbitrary number of bits to pins
byte pins[] = {2,3,4,5,6,7}; byte totalPins = 6; void setup(){ for(byte a = 0; a < totalPins; a++){ pinMode(pins[a], OUTPUT); } } void writeData(byte data, byte numberOfBits, byte startBit){ for(byte a = startBit; a < numberOfBits; a++){ if((data >> a) & 0x01){ digitalWrite(pins[a], HIGH); }else{ digitalWrite(pins[a], LOW); } } }
Scooter Code
- The following code is for controlling the scooter wirelessly.
struct data { byte start; byte left; byte right; byte finish; };
typedef struct data Packet;
Packet myData = {0, 0x55, 0x7e, 0};