AVR blinking 3 times, then read analog input to display


/*
Analog input, analog output, serial output

Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.

The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground

created 29 Dec. 2008
Modified 4 Sep 2010
by Tom Igoe
modified JUN-04-2011 by xiaolaba

This example code is in the public domain.

*/

// These constants won’t change. They’re used to give names
// to the pins used:
const int analogInPin = A7; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);

DDRD = B11111110; // sets D1-D7 as outputs, D0 as input
DDRD = DDRD | B11111100; // D2 – D7 outputs, D0 = TX, D1 = RX
DDRB = B00111111; //PORTB maps to D8 to D13, two high bits (6 & 7) map to the crystal pins, no use

PORTD = B11111111;
PORTB = B00111111;
delay(500); // wait for 0.2 second;
PORTD = 0x0;
PORTB = 0x0;
delay(500); // wait for 0.2 second;

PORTD = B11111111;
PORTB = B00111111;
delay(500); // wait for 0.2 second;
PORTD = 0x0;
PORTB = 0x0;
delay(500); // wait for 0.2 second;

PORTD = B11111111;
PORTB = B00111111;
delay(500); // wait for 0.2 second;
PORTD = 0x0;
PORTB = 0x0;
delay(500); // wait for 0.2 second;

PORTD = B11111111;
PORTB = B00111111;
delay(500); // wait for 0.2 second;
PORTD = 0x0;
PORTB = 0x0;
delay(500); // wait for 0.2 second;

PORTD = B11111111;
PORTB = B00111111;

delay(1000); // wait for 0.2 second;

}

void loop() {
/*
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
*/

// read the analog in value:
sensorValue = analogRead(A1);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(3, outputValue);

// read the analog in value:
sensorValue = analogRead(A3);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(5, outputValue);

// read the analog in value:
sensorValue = analogRead(A4);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(6, outputValue);

// read the analog in value:
sensorValue = analogRead(A5);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(12, outputValue);

// read the analog in value:
sensorValue = analogRead(A6);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(13, outputValue);

// read the analog in value:
sensorValue = analogRead(A7);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(9, outputValue);

// read the analog in value:
sensorValue = analogRead(A0);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(10, outputValue);

// read the analog in value:
sensorValue = analogRead(A2);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(11, outputValue);

// print the results to the serial monitor:
Serial.print(“sensor = " );
Serial.print(sensorValue);
Serial.print(“\t output = “);
Serial.println(outputValue);

// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}

hex
:200000000C9462000C948A000C948A000C948A000C948A000C948A000C948A000C948A00B8
:200020000C948A000C948A000C948A000C948A000C948A000C948A000C948A000C948A0070
:200040000C947C020C948A000C9458040C948A000C948A000C948A000C948A000C948A008A
:200060000C948A000C948A0000000000240027002A0000000000250028002B00000000003F
:20008000230026002900040404040404040402020202020203030303030301020408102071
:2000A0004080010204081020010204081020000000070002010000030406000000000000EB
:2000C0000000540511241FBECFEFD8E0DEBFCDBF11E0A0E0B1E0ECE2FFE002C005900D9271
:2000E000AA32B107D9F711E0AAE2B1E001C01D92AE3CB107E1F710E0C4ECD0E004C02297D7
:20010000FE010E949007C23CD107C9F70E948E050C9494070C9400006F927F928F929F929D
:20012000AF92BF92CF92DF92EF92FF920F931F938FE00E94580390932B0180932A0100D02C
:2001400000D0AA2797FDA095BA2FFFEF6F2E712C812C912CEDB7FEB761827282838294826F
:20016000BC01CD0120E030E040E050E0EFEFEE2EE3E0FE2E012D112DAA24BB2465010E948A
:20018000E9069B01AC0170932D0160932C010F900F900F900F9083E0B9010E947A0381E1BC
:2001A0000E94580390932B0180932A0100D000D0AA2797FDA095BA2FEDB7FEB76182728262
:2001C00083829482BC01CD0120E030E040E050E00E94E9069B01AC0170932D0160932C01EE
:2001E0000F900F900F900F9085E0B9010E947A0382E10E94580390932B0180932A0100D088
:2002000000D0AA2797FDA095BA2FEDB7FEB76182728283829482BC01CD0120E030E040E085
:2002200050E00E94E9069B01AC0170932D0160932C010F900F900F900F9086E0B9010E9425
:200240007A0383E10E94580390932B0180932A0100D000D0AA2797FDA095BA2FEDB7FEB7B7
:200260006182728283829482BC01CD0120E030E040E050E00E94E9069B01AC0170932D0196
:2002800060932C010F900F900F900F908CE0B9010E947A0384E10E94580390932B018093B9
:2002A0002A0100D000D0AA2797FDA095BA2FEDB7FEB76182728283829482BC01CD0120E01A
:2002C00030E040E050E00E94E9069B01AC0170932D0160932C010F900F900F900F908DE0AA
:2002E000B9010E947A0385E10E94580390932B0180932A0100D000D0AA2797FDA095BA2F12
:20030000EDB7FEB76182728283829482BC01CD0120E030E040E050E00E94E9069B01AC01CD
:2003200070932D0160932C010F900F900F900F9089E0B9010E947A038EE00E945803909320
:200340002B0180932A0100D000D0AA2797FDA095BA2FEDB7FEB76182728283829482BC0108
:20036000CD0120E030E040E050E00E94E9069B01AC0170932D0160932C010F900F900F9047
:200380000F908AE0B9010E947A0380E10E94580390932B0180932A0100D000D0AA2797FD8B
:2003A000A095BA2FEDB7FEB76182728283829482BC01CD0120E030E040E050E00E94E90658
:2003C0009B01AC0170932D0160932C010F900F900F900F908BE0B9010E947A030BEB11E0DC
:2003E000C80160E071E00E94CC0560912A0170912B01C8014AE050E00E94A406C8016AE065
:2004000071E00E94CC0560912C0170912D01C8014AE050E00E94CE066AE070E080E090E0C8
:200420000E94C4021F910F91FF90EF90DF90CF90BF90AF909F908F907F906F9008950F93FF
:200440001F938BEB91E040E855E260E070E00E9489048EEF8AB98AB18C6F8AB91FE314B9DD
:200460000FEF0BB915B964EF71E080E090E00E94C4021BB815B864EF71E080E090E00E945A
:20048000C4020BB915B964EF71E080E090E00E94C4021BB815B864EF71E080E090E00E9472
:2004A000C4020BB915B964EF71E080E090E00E94C4021BB815B864EF71E080E090E00E9452
:2004C000C4020BB915B964EF71E080E090E00E94C4021BB815B864EF71E080E090E00E9432
:2004E000C4020BB915B968EE73E080E090E00E94C4021F910F9108951F920F920FB60F921E
:2005000011242F933F938F939F93AF93BF938091320190913301A0913401B09135013091F3
:2005200036010196A11DB11D232F2D5F2D3720F02D570196A11DB11D209336018093320138
:2005400090933301A0933401B093350180912E0190912F01A0913001B09131010196A11DA8
:20056000B11D80932E0190932F01A0933001B0933101BF91AF919F918F913F912F910F9030
:200580000FBE0F901F9018959B01AC017FB7F89480912E0190912F01A0913001B091310122
:2005A00066B5A89B05C06F3F19F00196A11DB11D7FBFBA2FA92F982F8827860F911DA11DC8
:2005C000B11D62E0880F991FAA1FBB1F6A95D1F7BC012DC0FFB7F89480912E0190912F01D5
:2005E000A0913001B0913101E6B5A89B05C0EF3F19F00196A11DB11DFFBFBA2FA92F982FE3
:2006000088278E0F911DA11DB11DE2E0880F991FAA1FBB1FEA95D1F7861B970B885E93405D
:20062000C8F2215030404040504068517C4F211531054105510571F60895789484B5826058
:2006400084BD84B5816084BD85B5826085BD85B5816085BDEEE6F0E0808181608083E1E8F1
:20066000F0E01082808182608083808181608083E0E8F0E0808181608083E1EBF0E0808133
:2006800084608083E0EBF0E0808181608083EAE7F0E0808184608083808182608083808183
:2006A000816080838081806880831092C1000895982F8E3008F09E509770809116018295B9
:2006C000880F880F807C892B80937C0080917A00806480937A0080917A0086FDFCCF209127
:2006E000780040917900942F80E030E0282B392BC90108951F93CF93DF93182FEB0161E0ED
:200700000E94DA03209709F44AC0CF3FD10509F449C0E12FF0E0E255FF4F84918330C1F0D4
:20072000843028F4813051F08230B1F50CC0863019F1873049F1843079F514C084B580680B
:2007400084BDC7BD33C084B5806284BDC8BD2EC080918000806880938000D0938900C093C7
:20076000880024C080918000806280938000D0938B00C0938A001AC08091B00080688093A6
:20078000B000C093B30012C08091B00080628093B000C093B4000AC0C038D1051CF4812F0C
:2007A00060E002C0812F61E00E940004DF91CF911F910895482F50E0CA0186569F4FFC014A
:2007C00024914A575F4FFA0184918823C1F0E82FF0E0EE0FFF1FE859FF4FA591B491662314
:2007E00041F49FB7F8948C91209582238C939FBF08959FB7F8948C91822B8C939FBF08958B
:20080000482F50E0CA0182559F4FFC012491CA0186569F4FFC0134914A575F4FFA01949129
:20082000992309F444C0222351F1233071F0243028F42130A1F0223011F514C02630B1F04B
:200840002730C1F02430D9F404C0809180008F7703C0809180008F7D8093800010C084B518
:200860008F7702C084B58F7D84BD09C08091B0008F7703C08091B0008F7D8093B000E92F2F
:20088000F0E0EE0FFF1FEE58FF4FA591B491662341F49FB7F8948C91309583238C939FBFB9
:2008A00008959FB7F8948C91832B8C939FBF08951F920F920FB60F9211242F933F934F9371
:2008C0008F939F93EF93FF934091C600E091B701F091B80131969F012F7730703197809130
:2008E000B9019091BA012817390739F0E95CFE4F40833093B8012093B701FF91EF919F913E
:200900008F914F913F912F910F900FBE0F901F901895CF93DF93EC019A01AB01E885F985ED
:20092000203081EE380780E0480780E0580709F449C081E090E00A8802C0880F991F0A9433
:20094000E2F7808360E079E08DE390E00E9473072150304040405040CA01B90122E030E09E
:2009600040E050E00E947307EC81FD813083EE81FF812083EA85FB85208141E050E0CA012F
:200980000E8402C0880F991F0A94E2F7282B2083EA85FB852081CA010F8402C0880F991F48
:2009A0000A94E2F7282B2083EA85FB858081088802C0440F551F0A94E2F7842B8083DF9128
:2009C000CF910895108220E130E0CECFDC011296ED91FC911397E058FF4F219131918081A5
:2009E0009181281B390B2F773070C9010895DC011296ED91FC911397EE57FF4F2081318191
:200A000092918291E058F0408217930719F42FEF3FEF05C0E20FF31F8081282F30E0C901B2
:200A20000895DC011296ED91FC911397DF01AE57BF4F2D913C911197E058FF4F8081918120
:200A4000E058F0408217930719F42FEF3FEF0BC0E20FF31F80812F5F3F4F2F7730702D93B1
:200A60003C93282F30E0C9010895DC011296ED91FC911397EE57FF4F8081918192938293BF
:200A80000895FC01A085B18521898C9190E0022E02C0959587950A94E2F780FFF6CF0484AF
:200AA000F585E02D608308958BE191E09093BC018093BB0187E391E09093BE018093BD0115
:200AC00085EC90E09093C0018093BF0184EC90E09093C2018093C10180EC90E09093C4011F
:200AE0008093C30181EC90E09093C6018093C50186EC90E09093C8018093C70184E080935F
:200B0000C90183E08093CA0187E08093CB0185E08093CC0181E08093CD0108950E941D039E
:200B20000E941F020E948C00FDCF0F931F93CF93DF938C01EB0109C02196D801ED91FC91F3
:200B40000190F081E02DC801099568816623A1F7DF91CF911F910F910895EF92FF920F93A4
:200B60001F93CF93DF938C017B01EA010CC0D7016D917D01D801ED91FC910190F081E02DE8
:200B8000C80109952197209791F7DF91CF911F910F91FF90EF900895DC01ED91FC910280C2
:200BA000F381E02D099508952F923F924F925F926F927F928F929F92AF92BF92CF92DF924D
:200BC000EF92FF920F931F93DF93CF93CDB7DEB7A0970FB6F894DEBF0FBECDBF1C016A01BC
:200BE0007B01411551056105710549F440E350E060E070E020E030E00E946E0656C08824E9
:200C000099245401422E55246624772401E010E00C0F1D1F080D191DC701B601A30192018B
:200C20000E945107F80160830894811C911CA11CB11CC701B601A30192010E945107C901F4
:200C4000DA016C017D01C114D104E104F104F1F681E0E82EF12CEC0EFD1EE80CF91C3E0172
:200C60000894611C711CD501C4010197A109B1096C01C818D90816C0F601EE0DFF1D408164
:200C80004A3010F4405D01C0495C552747FD5095652F752FC10120E030E00E946E06089472
:200CA000E108F1086E147F0439F7A0960FB6F894DEBF0FBECDBFCF91DF911F910F91FF90F1
:200CC000EF90DF90CF90BF90AF909F908F907F906F905F904F903F902F900895EF92FF92D2
:200CE0000F931F93CF93DF93EC017A018B012115310541F4E881F9810190F081E02D642FB2
:200D000009951BC02A303105B1F477FF10C04DE250E060E070E020E030E00E946E06109525
:200D20000095F094E094E11CF11C011D111DCE01B801A7012AE00E94D405DF91CF911F919B
:200D40000F91FF90EF900895EF92FF920F931F937B019A010027F7FC0095102FB801A7017C
:200D60000E946E061F910F91FF90EF9008950F931F938C014DE050E060E070E020E030E084
:200D80000E946E06C8014AE050E060E070E020E030E00E946E061F910F910895CF92DF92A5
:200DA000EF92FF920F931F938C016B019A01EE24D7FCE094FE2CB701A6010E946E06C80178
:200DC0000E94B7061F910F91FF90EF90DF90CF9008952F923F924F925F926F927F928F9254
:200DE0009F92AF92BF92CF92DF92EF92FF920F931F93DF93CF93CDB7DEB73B014C01190168
:200E00002A016D897E898F89988D6A197B098C099D09621A730A840A950AA40193010E942A
:200E20003207E218F30804091509A80197010E9473072A0D3B1D4C1D5D1DB901CA01CF91A5
:200E4000DF911F910F91FF90EF90DF90CF90BF90AF909F908F907F906F905F904F903F906F
:200E60002F900895629FD001739FF001829FE00DF11D649FE00DF11D929FF00D839FF00DDA
:200E8000749FF00D659FF00D9927729FB00DE11DF91F639FB00DE11DF91FBD01CF01112405
:200EA0000895A1E21A2EAA1BBB1BFD010DC0AA1FBB1FEE1FFF1FA217B307E407F50720F02C
:200EC000A21BB30BE40BF50B661F771F881F991F1A9469F760957095809590959B01AC01A3
:200EE000BD01CF01089597FB092E05260ED057FD04D0D7DF0AD0001C38F450954095309576
:200F000021953F4F4F4F5F4F0895F6F790958095709561957F4F8F4F9F4F0895EE0FFF1F30
:200F20000590F491E02D0994F894FFCF73656E736F72203D200009206F7574707574203D45
:200F40002000010000000041059505AD05E6041105F704350500FFFFFFFFFFFFFFFFFFFFB3
:207800000C94343C0C94513C0C94513C0C94513C0C94513C0C94513C0C94513C0C94513C1D
:207820000C94513C0C94513C0C94513C0C94513C0C94513C0C94513C0C94513C0C94513CE0
:207840000C94513C0C94513C0C94513C0C94513C0C94513C0C94513C0C94513C0C94513CC0
:207860000C94513C0C94513C11241FBECFEFD8E0DEBFCDBF11E0A0E0B1E0ECE9FFE702C07E
:2078800005900D92A230B107D9F712E0A2E0B1E001C01D92AD30B107E1F70E942D3D0C94CC
:2078A000CC3F0C94003C982F9595959595959595905D8F708A307CF0282F295A8091C000B5
:2078C00085FFFCCF9093C6008091C00085FFFCCF2093C6000895282F205DF0CF982F8091CF
:2078E000C00085FFFCCF9093C6000895EF92FF920F931F93EE24FF2487018091C00087FD7B
:2079000017C00894E11CF11C011D111D81E4E81682E4F8068FE0080780E0180770F3E09106
:207920000401F091050109958091C00087FFE9CF8091C6001F910F91FF90EF9008950E949A
:20794000763C982F8091C00085FFFCCF9093C60091362CF490330CF09053892F08959755DB
:20796000892F08951F930E949F3C182F0E949F3C1295107F810F1F9108951F93182F882308
:2079800021F00E94763C1150E1F71F9108951F93182F0E94763C803249F0809103018F5FC1
:2079A000809303018530C1F01F9108958091C00085FFFCCF84E18093C6008091C00085FF4A
:2079C000FCCF1093C6008091C00085FFFCCF80E18093C6001F910895E0910401F0910501CF
:2079E00009951F9108950E94763C803241F0809103018F5F80930301853081F00895809177
:207A0000C00085FFFCCF84E18093C6008091C00085FFFCCF80E18093C6000895E0910401AC
:207A2000F09105010995089540E951E08823A1F02D9A28EE33E0FA013197F1F72150304072
:207A4000D1F72D9828EE33E0FA013197F1F721503040D1F7815061F708953F924F925F92B3
:207A60006F927F928F929F92AF92BF92CF92DF92EF92FF920F931F93CF93DF93000080E1A3
:207A80008093C4001092C50088E18093C10086E08093C2005098589A259A81E00E94143D43
:207AA00024E1F22E9EE1E92E85E9D82E0FE0C02E10E1B12EAA24A394B1E49B2EA6E58A2E44
:207AC000F2E57F2EE0E26E2E79E4572E63E5462E50E5352E0E94763C8033B1F18133B9F187
:207AE000803409F46FC0813409F476C0823409F485C0853409F488C0803531F1823521F128
:207B0000813511F1853509F485C0863509F48DC0843609F496C0843709F403C1853709F46A
:207B200072C1863709F466C0809103018F5F80930301853079F6E0910401F0910501099559
:207B40000E94763C803351F60E94F33CC3CF0E94763C803249F78091C00085FFFCCFF0928C
:207B6000C6008091C00085FFFCCF9092C6008091C00085FFFCCF8092C6008091C00085FFEA
:207B8000FCCF7092C6008091C00085FFFCCF6092C6008091C00085FFFCCF5092C6008091A1
:207BA000C00085FFFCCF4092C6008091C00085FFFCCF3092C6008091C00085FFFCCFB09214
:207BC000C60088CF0E94763C863808F4BDCF0E94763C0E94F33C7ECF0E94763C803809F473
:207BE0009CC0813809F40BC1823809F43CC1883909F48FC080E00E94C73C6CCF84E10E949F
:207C0000BD3C0E94F33C66CF85E00E94BD3C0E94F33C60CF0E94763C809306010E94763CA3
:207C2000809307010E94F33C55CF0E94763C803309F41DC183E00E94BD3C80E00E94C73C4F
:207C400049CF0E94763C809309020E94763C8093080280910C028E7F80930C020E94763C88
:207C6000853409F415C18091080290910902892B89F000E010E00E94763CF801E85FFE4F53
:207C800080830F5F1F4F80910802909109020817190788F30E94763C803209F045CF8091E0
:207CA0000C0280FF01C16091060170910701660F771F7093070160930601A0910802B091E8
:207CC00009021097C9F0E8E0F1E09B01AD014E0F5F1FF999FECF32BD21BD819180BDFA9A6C
:207CE000F99A2F5F3F4FE417F50799F76A0F7B1F70930701609306018091C00085FFFCCF16
:207D0000F092C6008091C00085FFFCCFB092C600E1CE83E00E94C73CDDCE82E00E94C73C8A
:207D2000D9CE0E94763C809309020E94763C809308028091060190910701880F991F909306
:207D40000701809306010E94763C853409F4A6C080910C028E7F80930C020E94763C80323E
:207D600009F0B8CE8091C00085FFFCCFF092C600609108027091090261157105B9F140E05F
:207D800050E080910C02A82FA170B82FB27011C0BB2309F45CC0E0910601F0910701319613
:207DA000F0930701E09306014F5F5F4F46175707E8F4AA2369F3F999FECF209106013091CA
:207DC000070132BD21BDF89A90B58091C00085FFFCCF9093C6002F5F3F4F30930701209354
:207DE00006014F5F5F4F4617570718F38091C00085FDE5CE8091C00085FFF8CFE0CE81E029
:207E00000E94C73C67CE0E94763C803209F08CCE8091C00085FFFCCFF092C6008091C000F6
:207E200085FFFCCFE092C6008091C00085FFFCCFD092C6008091C00085FFFCCFC092C6003B
:207E40008091C00085FFFCCFB092C60043CEE0910601F091070194918091C00085FFFCCFA3
:207E60009093C6009CCF80E10E94C73C33CE0E94763C0E94763C182F0E94763C112309F433
:207E800083C0113009F484C08FE00E94C73C22CE80910C02816080930C02E5CE80910C0226
:207EA000816080930C0259CF809107018823880F880B8A2180930B0280910601909107019E
:207EC000880F991F90930701809306018091080280FF09C0809108029091090201969093AA
:207EE000090280930802F894F999FECF1127E0910601F0910701C8E0D1E0809108029091A1
:207F00000902103091F40091570001700130D9F303E000935700E895009157000170013067
:207F2000D9F301E100935700E895099019900091570001700130D9F301E000935700E8954C
:207F40001395103498F011270091570001700130D9F305E000935700E8950091570001707A
:207F60000130D9F301E100935700E8953296029709F0C7CF103011F00296E5CF11248091F8
:1E7F8000C00085FFB9CEBCCE8EE10E94C73CA2CD85E90E94C73C9ECDF894FFCF8000B3
:00000001FFl=0xffh=0xdae=0x05lc=0x0f

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s