Devices & Components
Arduino Uno Rev3
Software & Tools
Arduino IO
Project description
Code
arduino to PC
arduino
1/* 2 * IO 3 * Created: 12/08/2017 23:34:47 4 * Author: moty22.co.uk 5*/ 6 7unsigned char inByte=0, outByte=0; // 8 9// the setup function runs once when you press reset or power the board 10void setup() { 11 // initialize serial communication at 9600 bits per second: 12 Serial.begin(9600); 13 // initialize outputs 8-13 inputs 2-7 analogue A0-A3 14 pinMode(8, OUTPUT); 15 pinMode(9, OUTPUT); 16 pinMode(10, OUTPUT); 17 pinMode(11, OUTPUT); 18 pinMode(12, OUTPUT); 19 pinMode(13, OUTPUT); // 20 21} 22 23// the loop function runs over and over again forever 24void loop() { 25 unsigned char i; 26 27 if (Serial.available() > 0) { 28 // read the incoming byte: 29 inByte = Serial.read(); 30 31 if(inByte < 128) 32 { 33 PORTB = inByte; //update digital outputs 8-13 34 } 35 if(inByte == 128) //128 = a request for update 36 { 37 Serial.write(lowByte(analogRead(A0))); //send low byte of 10 bits analogue read 38 Serial.write(highByte(analogRead(A0))); //send high byte of 10 bits analogue read 39 Serial.write(lowByte(analogRead(A1))); 40 Serial.write(highByte(analogRead(A1))); 41 Serial.write(lowByte(analogRead(A2))); 42 Serial.write(highByte(analogRead(A2))); 43 Serial.write(lowByte(analogRead(A3))); 44 Serial.write(highByte(analogRead(A3))); 45 //read the 6 digital inputs 2-7 and put them in a byte 46 for(i=0;i<6;i++){ 47 bitWrite(outByte, i, digitalRead(i+2)); 48 } 49 Serial.write(outByte); 50 } 51 } 52} 53 54 55
Downloadable files
pinout
pinout

pinout
pinout

Comments
Only logged in users can leave comments