Changes between Version 32 and Version 33 of wade/embedded/arduino/example/temp


Ignore:
Timestamp:
Jun 7, 2013, 4:22:14 PM (11 years ago)
Author:
wade
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • wade/embedded/arduino/example/temp

    v32 v33  
    825825}}}
    826826
     827= 程式十六:led 與 x_y 搖桿 =
     828{{{
     829void setup() {
     830  for (int i = 2; i <= 17; i++)
     831  {
     832    pinMode(i, OUTPUT);
     833  }
     834  clean();
     835  Serial.begin(9600);
     836}
     837
     838void loop() {
     839  // put your main code here, to run repeatedly:
     840  int val_x = analogRead(4);
     841  int val_y = analogRead(5);
     842  Serial.print("   x: ");
     843  Serial.print(val_x);
     844  Serial.print("   y: ");
     845  Serial.println(val_y);
     846 
     847 
     848  if ( 0 <=val_x && val_x < 128)
     849  {
     850//    Serial.println(" range 1");
     851  digitalWrite(2, HIGH);
     852  digitalWrite(10, LOW);
     853  }
     854  if ( 128 <=val_x && val_x < 256)
     855  {
     856//    Serial.println(" range 2");
     857  digitalWrite(2, HIGH);
     858  digitalWrite(10, LOW);
     859  digitalWrite(11, LOW);
     860  }
     861  if ( 256 <=val_x && val_x < 384)
     862  {
     863//    Serial.println(" range 3");
     864  digitalWrite(2, HIGH);
     865  digitalWrite(10, LOW);
     866  digitalWrite(11, LOW);
     867  digitalWrite(12, LOW);
     868  }
     869  if ( 384 <=val_x && val_x < 512)
     870  {
     871//    Serial.println(" range 4");
     872  digitalWrite(2, HIGH);
     873  digitalWrite(10, LOW);
     874  digitalWrite(11, LOW);
     875  digitalWrite(12, LOW);
     876  digitalWrite(13, LOW);
     877  }
     878  if ( 512 <=val_x && val_x < 640)
     879  {
     880//    Serial.println(" range 5");
     881  digitalWrite(2, HIGH);
     882  digitalWrite(10, LOW);
     883  digitalWrite(11, LOW);
     884  digitalWrite(12, LOW);
     885  digitalWrite(13, LOW);
     886  digitalWrite(14, LOW);
     887  }
     888  if ( 640 <=val_x && val_x < 768)
     889  {
     890//    Serial.println(" range 6");
     891  digitalWrite(2, HIGH);
     892  digitalWrite(10, LOW);
     893  digitalWrite(11, LOW);
     894  digitalWrite(12, LOW);
     895  digitalWrite(13, LOW);
     896  digitalWrite(14, LOW);
     897  digitalWrite(15, LOW);
     898  }
     899  if ( 768 <=val_x && val_x < 896)
     900  {
     901//    Serial.println(" range 7");
     902  digitalWrite(2, HIGH);
     903  digitalWrite(10, LOW);
     904  digitalWrite(11, LOW);
     905  digitalWrite(12, LOW);
     906  digitalWrite(13, LOW);
     907  digitalWrite(14, LOW);
     908  digitalWrite(15, LOW);
     909  digitalWrite(16, LOW);
     910  }
     911  if ( 896 <=val_x && val_x < 1024)
     912  {
     913//    Serial.println(" range 8");
     914  digitalWrite(2, HIGH);
     915  digitalWrite(10, LOW);
     916  digitalWrite(11, LOW);
     917  digitalWrite(12, LOW);
     918  digitalWrite(13, LOW);
     919  digitalWrite(14, LOW);
     920  digitalWrite(15, LOW);
     921  digitalWrite(16, LOW);
     922  digitalWrite(17, LOW);
     923  }
     924  delay(10);
     925  clean();
     926}
     927
     928void clean()
     929{
     930  for (int i = 2; i <= 9; i++)
     931  {
     932    digitalWrite(i, LOW);
     933  }
     934  for (int i = 10; i <= 17; i++)
     935  {
     936    digitalWrite(i, HIGH);
     937  }
     938}
     939}}}
     940
    827941[[Image(LED8x8-2.png)]]
    828942[[Image(四方型.png)]]